How to count the each number of row within a array in matlab

1.1k Views Asked by At

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

There are 1 best solutions below

0
On

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