Check an entire matrix against each value of another matrix
1 view (last 30 days)
I have the following code;
- I want to check matrix b against each value of matrix a, and extract values in matrix b based on a condition.
- The condition when delta 1 == 0, the value of matrix b corresponding to 0 is extracted into c.
However, I am getting an error Index in position 1 exceeds array bounds (must not exceed 1) in the line below. I have 2 questions:
- Why is this error happening?
- Is there another way to accomplish this without using loops?
a = [4 3];
b = [1 4.2 5 6 7 3.2];
c = zeros(size(a));
for i = 1:length(a)
delta1(i,:) = abs((b-a(i))/a(i));
for j = 1:length(delta1)
if delta1(i,j) < 0.3
c(i) = b(i,j); % This line