how to extract another matrix out of a big matrix

2 ビュー (過去 30 日間)
farfar
farfar 2017 年 9 月 11 日
コメント済み: farfar 2017 年 9 月 11 日
Hello I have a big matrix including many rows and 2 columns. first column is the wavelengths. I need to extract another matrix out of it based on some specific wavelength value and I dont need the rest of data. for example this is my main matrix:
A=[420 0.23;421 0.26;422 0.25;423 0.24;424 0.28;425 0.27]
but I know that I just need values corresponding to (420 422 425) in the first column , so what i need is:
B=[420 0.23;422 0.25;425 0.27]
how can I ask to extract data for these three specific values in the first column? I cant refer to them by their position in matrix since it is not fix. thanks !

採用された回答

James Tursa
James Tursa 2017 年 9 月 11 日
v = [420,422,425];
B = A(ismember(A(:,1),v),:);

その他の回答 (1 件)

Stephen23
Stephen23 2017 年 9 月 11 日
>> A=[420 0.23;421 0.26;422 0.25;423 0.24;424 0.28;425 0.27]
A =
420 0.23
421 0.26
422 0.25
423 0.24
424 0.28
425 0.27
>> idx = ismember(A(:,1),[420,422,425]);
>> A(idx,:)
ans =
420 0.23
422 0.25
425 0.27
  1 件のコメント
farfar
farfar 2017 年 9 月 11 日
Thank you people

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

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by