Q:

Using logical operation on sorted array (keep sorted array after logical operation)

Idea
I have the following problem.  In order to increase my code speed I am trying to write most of my script as logical operation rather then as for-loops or the like. 
Problem
I have a sorted array and I want to keep it sorted as I need it sorted as input for the next function.  In order to do so I used the following code:
target_level=sortrows(target_level,-9);
for i= 1:length(target_level);
   ii=find(BML(:,1)==target_level(i,1));
   targets(1,i)=ii;
end 

So I want to find the index of the matrix BML for every element of     "target_level(:,1)", while keeping the sorting.  In order to loose the for-loop and write this as a logical operation I tried:
targets=ismember(BML(:,1),target_level(:,1));
targets=find(targets(:,1)==1);

It comes up with the same results, the only problem is that I loose the sorting which I applied on a variable that I dont really want to keep.  
Question
Is there a way to keep the sorting while using logical operations? 

A:

To get the indexes while keeping the sorting you can simply use the second output of ismember:
[~, targets] = ismember(BML(:,1),target_level(:,1));

Best,

