1

I have a matrix like- [1 2 3 3 3;1 2 2 5 5] From this matrix, I want to calculate in matlab that in each row how many numbers of 1 2 3 and 5? The result will be - 1 1 2; 1 2 2

I have tried with numberof1=sum(a(1:ac,:)==1); but this is valid if there is only one row but in my case there are multiple rows so i need to check every rows.

I really need help.

1 Answers1

1

You can use ==1 on the entire matrix A, and then sum along the rows. As in sum(a==1,2); (see sum documentation).

40 votes
  • 9,736