How can I detect the difference b/w indices of vector and stop it as well?
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Marc Jakobi
2016 年 10 月 7 日
編集済み: Marc Jakobi
2016 年 10 月 7 日
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 件のコメント
Marc Jakobi
2016 年 10 月 8 日
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
その他の回答 (1 件)
Massimo Zanetti
2016 年 10 月 7 日
編集済み: Massimo Zanetti
2016 年 10 月 7 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!