Find each element that is less than some element to its right

后端 未结 6 1656
滥情空心
滥情空心 2021-01-12 03:05

I need to find elements of a vector that are less than one of more elements that come after it. It\'s easy to do in a loop:

x = some_vector_values;
for m = 1         


        
6条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-12 04:04

    @NKN has it right. Sort.

    x = some_vector_values;  
    
    [Y,I]=sort(x);  %sort in order, get indices
    dy=gradient(Y); %get difference vector same size as input vector
    ind=find(dy~=0);%ignore places that are equal to the value of interest
    
    for m = 1 : length(ind)
        do_such_and_such to Y(ind(m));
    end
    

    Best of luck

提交回复
热议问题