MATLAB: How to detect the difference b/w indices of vector and stop it as well

differencestop the loop

Hi, I'm doing my research on recovering spectrum. For that i'm proposing an algorithm which is much like Block Orthogonal Matching pursuit(BOMP). But the problem I'm facing is that I want my algorithm to detect the difference b/w indices of vector and stop the loop if the difference is greater than set threshold? To achieve that I'm doing this, which isn't right. A=100*100 matrix and r is 100*1 matrix.
xt=A*r;
x=find(xt>(max(abs(xt))-threshold));
for j=2:1:length(x)
xdiff(j)=x(j)-x(j-1)<Other_threshold;
break;
end
Thanks;
WN

Best Answer

You should include an IF statement
x_diff = abs([inf; diff(x)]);
ind = find(x_diff < Other_threshold, 1); %index where difference is smaller than threshold
for i = 1:ind
% do stuff
end
Related Question