How to write a loop to count the number of instances of a certain number occurring in each row?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Joelle Martin
am 2 Okt. 2015
Kommentiert: Joelle Martin
am 5 Okt. 2015
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!
0 Kommentare
Akzeptierte Antwort
dpb
am 2 Okt. 2015
Use the second, optional argument to sum--
s=sum(m==2,2); % doc sum for details...
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!