How to extract parts of an array by given logical conditions?

4 ビュー (過去 30 日間)
Emerson De Souza
Emerson De Souza 2014 年 6 月 9 日
コメント済み: Emerson De Souza 2014 年 6 月 9 日
Hi, I have an array, let's say
M=
1 1 0
1 2 0
1 3 1
2 1 0
2 2 1
2 3 1
and I would like to create a new array only with the case for which the value of the third column equals 1. Thus
N=
1 3 1
2 2 1
2 3 1

採用された回答

Image Analyst
Image Analyst 2014 年 6 月 9 日
Try this:
M=[...
1 1 0
1 2 0
1 3 1
2 1 0
2 2 1
2 3 1]
rowsToExtract = M(:,3)==1;
N = M(rowsToExtract,:)
  1 件のコメント
Emerson De Souza
Emerson De Souza 2014 年 6 月 9 日
Thank you Image Analyst,
your suggestion elegantly solved my problem.
Wish you a nice day
Emerson

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by