필터 지우기
필터 지우기

How to write a loop to count the number of instances of a certain number occurring in each row?

조회 수: 3 (최근 30일)
I have a matrix (m) that is 159 rows and 6 columns. There are 1s, 2s, and NaNs. I need to count the number of times a '2' happens in each row. Please help! I wrote sum(m(26,:) == 2) but it is too tedious to do 159 times!

채택된 답변

dpb
dpb 2015년 10월 2일
Use the second, optional argument to sum--
s=sum(m==2,2); % doc sum for details...

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by