フィルターのクリア

Find similar elements in a matrix

5 ビュー (過去 30 日間)
Niki
Niki 2011 年 9 月 5 日
My question is that , I have a matrix, I want to know which element from which columns are similar, which number is the most repeated number for example
X=[1 2 3 3 3
45 7 4 4 4
70 8 5 5 5
88 9 11 11 11
170 205 13 13 13
172 220 14 23 24
194 222 24 24 41
196 224 41 152 67
200 539 62 183 68
250 540 67 184 71
251 1415 68 185 148
255 1426 71 187 151
]
for example here 3 (repeated in columns 3,4 and5) the same for 4, 5, 1, 13
and the most repeated numbers are 3,4,5,11, and 13
  2 件のコメント
Grzegorz Knor
Grzegorz Knor 2011 年 9 月 5 日
I've question:
most repeated numbers are 3,4,5,11, and 13
or rather
most repeated numbers are 3,4,5,11, 13 and 24?
Niki
Niki 2011 年 9 月 5 日
you are right
3,4,5,11, 13 and 24

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

採用された回答

Grzegorz Knor
Grzegorz Knor 2011 年 9 月 5 日
[h1 h2] =hist(X(:),unique(X));
h3 = unique(h1);
h3 = h3(end:-1:1);
for k=1:length(h3)
disp(['There is ' num2str(h3(k)) ': [ ' num2str(h2(h1==h3(k))') ' ]'])
end
  2 件のコメント
Grzegorz Knor
Grzegorz Knor 2011 年 9 月 5 日
If you think that this answer solved your problem, please accept it :)
Niki
Niki 2011 年 9 月 5 日
Grzegorz, It works , thanks , also could you please take a look at one another question that I have?

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

その他の回答 (2 件)

Daniel Shub
Daniel Shub 2011 年 9 月 5 日
Maybe something like:
[y, z] = hist(X(:), unique(X));
stem(z, y);
  1 件のコメント
Niki
Niki 2011 年 9 月 5 日
Thanks Daniel, your comments always make a brilliant way,

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


Grzegorz Knor
Grzegorz Knor 2011 年 9 月 5 日
My suggestion:
[u, ~, n] = unique(X);
[h1 h2] =hist(n,unique(n));
u(h2(h1==max(h1)))
  3 件のコメント
Grzegorz Knor
Grzegorz Knor 2011 年 9 月 5 日
There is 45 zeros:
sum(X(:)==0)
Is this OK?
Niki
Niki 2011 年 9 月 5 日
Yes, exactly
It is okay, but I would like to see the others as well, for example 45 times zero, then 3,4,5,11, 13 and 24

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

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by