is it possible to detect repeated values in a matrix?how?

9 ビュー (過去 30 日間)
husot
husot 2014 年 1 月 21 日
コメント済み: husot 2014 年 1 月 21 日
For example I have a matrix such;
A=[5 13 2 7 1 8; 2 4 5 7 8 23 31;5 65 34 12 31 8]
which has a size (nx6)
If we look through first column, first and third row values are same. I just want to detect the repeated values in the 1st column in all rows. How can I do that?
Thanks

採用された回答

AJ von Alt
AJ von Alt 2014 年 1 月 21 日
This can be done using hist and unqiue. See How can I count the occurrences of each element in a vector in MATLAB? for more information.
A=[5 13 2 7 1 8; 2 4 5 7 8 23;5 65 34 12 31 8];
% Find the unique values
uniqueVals = unique( A(:,1) );
% Count the number of instances of each of the unique vals
valCount = hist( A(:,1) , uniqueVals )';

その他の回答 (1 件)

Matt J
Matt J 2014 年 1 月 21 日
length(unique(A(:,1)))<size(A,1)
  3 件のコメント
Matt J
Matt J 2014 年 1 月 21 日
編集済み: Matt J 2014 年 1 月 21 日
How about
[U,I]=unique(A(:,1));
repeated = setdiff(1:size(A,1), I),
For your example, this returns 3 because row 3 is a repetition of row 1. If this isn't what you want, see the documentation for UNIQUE. It gives you lots of different options for analyzing repetition.
husot
husot 2014 年 1 月 21 日
I made it, thanks!

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

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by