フィルターのクリア

Pulling subset from a 2D matrix

6 ビュー (過去 30 日間)
Simon
Simon 2013 年 9 月 5 日
Hi,
I am struggling how to extract part of a 2D matrix based on logical criteria:
example:
a=[1 1 1 ; 2 2 2 ; 3 3 3]
b=a<3 % let say I want to have the subset where a<3
mySubset=a.*b
how can I obtain the subset using logic and not having a line of zeros where a=3?
Thanks

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 9 月 5 日
編集済み: Azzi Abdelmalek 2013 年 9 月 5 日
a=[1 1 1 ; 2 2 2 ; 3 3 3]
b==a<3
mySubset=a.*b
  4 件のコメント
Simon
Simon 2013 年 9 月 5 日
Thanks! I was not aware of the function all()
Roger Stafford
Roger Stafford 2013 年 9 月 5 日
The 'all' method only works if all elements of a row in 'a' are less than 3. In general I think what you really want is
mySubset = a(b);
The result will be a one-dimensional array but in the general case that is unavoidable.

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

その他の回答 (0 件)

カテゴリ

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