How can I detect the difference b/w indices of vector and stop it as well?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Wajeeha Nasar
el 7 de Oct. de 2016
Comentada: Marc Jakobi
el 8 de Oct. de 2016
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
0 comentarios
Respuesta aceptada
Marc Jakobi
el 7 de Oct. de 2016
Editada: Marc Jakobi
el 7 de Oct. de 2016
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
2 comentarios
Marc Jakobi
el 8 de Oct. de 2016
I'm not quite sure I understand what you're trying to do. But I'll give it a try.
si = x_diff < S_threshold;
creates a logical vector with the same size as x_diff with true in the positions where x_diff is smaller than S_threshold and false where x_diff is greater than or equal to S_threshold. So you might want to do it like this:
si = x_diff < S_threshold;
s1 = x(si); % values smaller than S_threshold
s2 = x(~si); % values greater than S_threshold
S = [s1, s2]; % note: This only works if s1 and s2 are the same size
% i. e. there must be as many values in x_diff that are greater than or equal to S_threshold
% as there are values that are smaller than S_threshold
Más respuestas (1)
Massimo Zanetti
el 7 de Oct. de 2016
Editada: Massimo Zanetti
el 7 de Oct. de 2016
To get the differences between all consecutive values of x, better use the built-in matlab function diff(), and then thresholding the result:
%logical vector where ones are places where diff(x) is less than other_thr
I=diff(x)<other_thr
If you need to know the first index k at which x(k+1)-x(k)<other_thr, you can have it by
k = find(I)
0 comentarios
Ver también
Categorías
Más información sobre Matrices and Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!