How to get the index from a matrix?
Show older comments
Hi. I have a problem where I need to update the index value with a larger index if elements in A greater than B..
A = [2;7.5;9;10.5;15;14]; % Also can be in random numbers A and B are different in size
B = 5:5:50 % Fixed numbers
idx = ones(size(A,1),1; % Set to one if A less than B
for i = 1:size(A,1)
[~,idx(i)] = ismembertol(A(i),B,0.05);
end
% Results
idx = [0;1;2;2;3;3]
%Which I want to get
idx = [1;2;2,3,4,3]
Please help, and thanks in advance.
Accepted Answer
More Answers (0)
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!