Reputation: 115
I have a matrix A(97x13) ranging from 0 to 90
I would like to find in specific rows which values are lower than 45.
find(A(:,[4,7,10])<45);
My problem is that I don't know how to relate the resulting indices with the entire A matrix.
Can someone help me with that?
Upvotes: 0
Views: 56
Reputation: 112659
The result is in the form of a linear index. You can convert to row and column using ind2sub
:
cols = [4,7,10];
ind = find(A(:,cols)<45);
[r, c] = ind2sub([size(A,1) numel(rows)], ind);
c = cols(c); %// change from "1,2,3" to "4,7,10"
To save some running time, you can use a "manual" version of ind2sub
:
cols = [4,7,10];
ind = find(A(:,cols)<45);
r = mod(ind-1,size(A,1))+1;
c = cols(ceil(ind/size(A,1)));
Example:
A =
8 66 87 57 4 24 10 82 3 55
24 44 50 62 80 31 59 81 67 56
73 53 47 36 83 62 45 31 46 78
3 22 21 34 72 13 71 63 44 73
84 42 45 89 9 65 65 18 82 52
gives
r =
3
4
1
c =
4 4 7
Upvotes: 2