フィルターのクリア

Apply condition to specific column and extract data from that row

9 ビュー (過去 30 日間)
Kanbodin
Kanbodin 2022 年 10 月 4 日
回答済み: Angelo Yeo 2022 年 10 月 4 日
Hi, I'm working with a matrix with 3 column and n amount of rows
I want to apply a condition to the 1st and 2nd column, then extract the data from the 3rd column which the condition is matched.
for example, I have A =
1 2 3
2 6 6
1 8 5
3 2 7
8 4 3
6 8 1
I want to extract the data from 3rd cloumn in the row where the condition are,
  • value of the 1st column in less that 5
  • value of the 2nd column is more that 5,
Therefore, I will have data from 2nd and 3rd row (6 and 5)

回答 (1 件)

Angelo Yeo
Angelo Yeo 2022 年 10 月 4 日
A = [1 2 3
2 6 6
1 8 5
3 2 7
8 4 3
6 8 1];
idx_row = (A(:,1) < 5) & (A(:,2) > 5);
A(idx_row,:)

カテゴリ

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

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by