It should be simple, but surprisingly, I could not find the answer to this problem here or through trial and error.
I want to get the values from the matrix (according to some condition) and put the values in the vector. I also need indexes of indices of the corresponding values. There is a lot of data, so no for loops.
This is the correct (but iterative) answer:
[I,J] = find(A > 5);
values = zeros(numel(I),1);
for i=1:numel(I)
values(i) = A(I(i),J(i));
end
I tried values = A(I,J), but it is n-by-n instead of n-by-1.
source
share