Count the frequent numbers in the matrix based on the sequence in the matrix ?

7 ビュー (過去 30 日間)
fathi
fathi 2017 年 3 月 22 日
コメント済み: fathi 2017 年 4 月 30 日
I like to count the frequent numbers in the matrix based on the sequence in the matrix /// EX: Y = [ 5 4 4 2 ; 6 3 3 1 ;2 4 2 2; 5 5 6 1] The answer suppose to be like: 5 3, 4 3, 2 4 , 6 2, 3 2, 1 2 /// That mean the 5 repeated 2 times, the 4 repeated three times and so on .. /// The an important point is the number based on the sequence in the matrix which 5,4,2,6,3,1 /// not Descending or Ascending /// thanks

採用された回答

the cyclist
the cyclist 2017 年 3 月 22 日
Here's one way:
Y = [ 5 4 4 2 ; 6 3 3 1 ;2 4 2 2; 5 5 6 1];
YT = Y';
[uniqueY, ~, j] = unique(YT(:),'stable');
ycounts = histcounts(j,[unique(j); Inf]);
output = [uniqueY,ycounts']
  5 件のコメント
fathi
fathi 2017 年 4 月 15 日
Thank you, my friend, for your reply.It works. that is what I want exactly.
fathi
fathi 2017 年 4 月 30 日
good morning .. if I have 40 figures from the up ( last answer one ) from different 40 matrixes with 4*4 dim //// how can I represent them by one figure? I mean one generalized graph?

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by