Find first row with certain value in x2 array

I have an 300x2 array in which I need to find a certain numbert in colum 1, e.g. 10. Once the number is found I need to extract the corresponding value in colum 2.

1 件のコメント

dpb
dpb 2021 年 6 月 8 日
Read on logical indexing ...

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

 採用された回答

Chunru
Chunru 2021 年 6 月 8 日

1 投票

idx = A(:, 1) == 10; % find the index that 1st column = 10
b = A(idx, 2); % extract the corresponding data in 2nd column
Or in one line
b = A(A(:,1)==10, 2);

1 件のコメント

Gevin Schaeffer
Gevin Schaeffer 2021 年 6 月 8 日
Thanks :) ! it is really that simple. I literally just started with MATLAB

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

製品

リリース

R2020b

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by