필터 지우기
필터 지우기

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 CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by