フィルターのクリア

if column a=[1;2;3;2;5;2], b=[1;2;3;4;5;6] how many rows have a==2, i use this [a]=find(a==2) .

1 回表示 (過去 30 日間)
My question is on that a==2 row what is the value of row of column b.

採用された回答

madhan ravi
madhan ravi 2018 年 12 月 22 日
編集済み: madhan ravi 2018 年 12 月 22 日
a=[1;2;3;2;5;2];
b=[1;2;3;4;5;6];
how_many_rows_have_2_in_a = nnz(a==2)
corresponding_b_value_when_a_is_2 = b(a==2)
Gives:
how_many_rows_have_2_in_a =
3
corresponding_b_value_when_a_is_2 =
2
4
6
If you still want to use find then:
how_many_rows_have_2_in_a = numel(find(a==2))
corresponding_b_value_when_a_is_2 = b(find(a==2))
Gives:
how_many_rows_have_2_in_a =
3
corresponding_b_value_when_a_is_2 =
2
4
6
Note : Logical indexing is efficient than find.
  3 件のコメント
john karli
john karli 2018 年 12 月 22 日
Thanks alot its work for me sir
madhan ravi
madhan ravi 2018 年 12 月 22 日
Anytime :)

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

その他の回答 (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