Finding the number of occurance of each value in the each columns of a matrix.

2 views (last 30 days)
Hi there
I have a doubt in calculating frequency of repeating value.
Lets say I have a matrix 'FCL21' of m X n. n if fixed lets say 12 but m may vary according to filter in excel data.
the elements of matrix may have values 1 to 9 and 1/2 to 1/9 .
For further calculations, I need to create an matrix containing frequency of each value.
I used
XFCL21 = [sum(FCL21==1);sum(FCL21==2);sum(FCL21==3);sum(FCL21==4);sum(FCL21==5); ...
sum(FCL21==6);sum(FCL21==7);sum(FCL21==8);sum(FCL21==9); ...
sum(FCL21==1./2);sum(FCL21==1./3);sum(FCL21==1./4);sum(FCL21==1./5); ...
sum(FCL21==1./6);sum(FCL21==1./7);sum(FCL21==1./8);sum(FCL21==1./9);];
It is working well for m >1. But if in some cases m = 1, It is giving me the counting from the row. that i dont need.
It suppose to give me the counting from columns only. If m = 1 and and an element have value 3 in first row and first column then in XFCL21 should
1 at 3rd row 1st column and remaining element of the column should be 0.
Please suggest me some better ways to overcome this problem.
Thanks in advance.
Regards
Ashwani
  4 Comments
Ashwani Kumar MAlviya
Ashwani Kumar MAlviya on 16 Jun 2020
Dear KSSV
unique result is not somthing I am looking for. It is shorting the columns. Can you please explain me more?

Sign in to comment.

Accepted Answer

Divya Gaddipati
Divya Gaddipati on 25 Jun 2020
A similar question has already been asked and answered by the community which could be of relevance to you.
You can refer to the below link:

More Answers (0)

Community Treasure Hunt

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

Start Hunting!