フィルターのクリア

how to count occurrences of a variable in a matrix?

1 回表示 (過去 30 日間)
Võ Kiet
Võ Kiet 2021 年 8 月 6 日
コメント済み: Võ Kiet 2021 年 8 月 6 日
Hi, I am stuck with my problem.
I have a matrix A = {'Red', 'Blue', 'Green', 'Yellow', 'White'; 'Red', 'Black', 'Purple', 'Red', 'White'}.
Now I want to count occurrences of 'Red' in this matrix. But I don't know how to count it. Please help me resolve this problem!
Thanks and Best Regards,
Kiet Vo

採用された回答

KSSV
KSSV 2021 年 8 月 6 日
A = {'Red', 'Blue', 'Green', 'Yellow', 'White'; 'Red', 'Black', 'Purple', 'Red', 'White'} ;
nnz(strcmp(A,'Red'))
ans = 3
  1 件のコメント
Võ Kiet
Võ Kiet 2021 年 8 月 6 日
nice!!! Thanks you so much, you saved me. Again, thanks so much.
Best Regards,
Kiet Vo

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by