find values around a given row value

I have a 2 column matrix where I have a row of interest. i.e.
A =
2.5000 2.3500
2.5600 3.3300
2.4500 3.1000
etc....
and I want to find say 100 rows past the row of interest (2.5 2.35) (i.e. down the matrix). Is there a function for this? thanks.

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 11 月 25 日
編集済み: Azzi Abdelmalek 2013 年 11 月 25 日

1 投票

idx=find(ismember(A,[ 2.5000 2.3500],'rows'),1)
out=A(idx+1:idx+100,:)

6 件のコメント

MacKenzie
MacKenzie 2013 年 11 月 25 日
編集済み: MacKenzie 2013 年 11 月 25 日
great, thanks! what if I have the index (since the values often repeat in my matrix) of the A position I want, then I want the next 100 values put into a new matrix? i.e. I should loop this since I have 20+ values in the matrix to find and graph the next 100 values....
for i= 1:length(TS) %TS is the indx of values I want to find in A
idx = TS(i)
out(i) = A(idx:idx+100,:);
end
?
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 11 月 25 日
idx=find(ismember(A,[ 2.5000 2.3500],'rows'))
out=arrayfun(@(x) A(x+1:x+100,:),idx,'un',0)
MacKenzie
MacKenzie 2013 年 11 月 25 日
編集済み: MacKenzie 2013 年 11 月 25 日
cool. so assuming I have the idx already (some other matrix, TS), easy way to loop this?
I tried:
for i= 1:length(TS)
idx = TS(i);
out=arrayfun(@(x) sFNxy(x+1:x+500,:),idx,'un',0);
end
but it works only for the first value in my matrix TS - am I missing something?
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 11 月 25 日
You are erasing the variable out each iteration. just write
out=arrayfun(@(x) sFNxy(x+1:x+500,:),TS,'un',0);
MacKenzie
MacKenzie 2013 年 11 月 25 日
Ah! thanks SO much!
Walter Roberson
Walter Roberson 2017 年 10 月 14 日
QIANG SUN comments to Azzi:
great!

サインインしてコメントする。

その他の回答 (1 件)

Youssef  Khmou
Youssef Khmou 2013 年 11 月 25 日

0 投票

you can use minimum absolute value as the following :
% data generation
p1=2.5;p2=2.35;
A=ones(600,2);
A(:,1)=A(:,1)*p1;
A(:,2)=A(:,2)*p2;
A=A+randn(size(A); % additive noise
%processing
eps=0.02;
B(:,1)=abs(A(:,1)-p1);
B(:,2)=abs(A(:,2)-p2);
Result=B(B<eps);

カテゴリ

ヘルプ センター および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by