I have two arrays of different size A and B. I am comparing A to B and want to find for each element in A the first element in B that is smaller/larger.
I would like to use something like ismember(A,B), except that I am not looking for identical elements. The problem is that ‘find’ will not work because A and B are not the same size.
I now used a loop but am looking for a more elegant way to program this. Here is the loop:
for zz=1:length(A)
tmpmax(zz) = find(B>=A(zz),1);
tmpmin(zz) = find(B<=A(zz),1,'last');
end
Thanks for your suggestions!
Immo
You can get rid of the loop with: