フィルターのクリア

find the repetition of matrix rows

6 ビュー (過去 30 日間)
yousef Yousef
yousef Yousef 2014 年 5 月 7 日
編集済み: Image Analyst 2014 年 5 月 9 日
I want to find out if the row i of mxn matrix is repeated ,the code should give logic 1.Otherwise zero"there are many ways but Im searching for the best one" Thanks
  2 件のコメント
Cedric
Cedric 2014 年 5 月 7 日
Please provide an example.
José-Luis
José-Luis 2014 年 5 月 7 日
And please instead of asking an almost repeated question, try to explain better what you want, and please show some effort before asking for a ready-made answer.

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

採用された回答

Roberto
Roberto 2014 年 5 月 9 日
編集済み: Roberto 2014 年 5 月 9 日
a = [1 2 3; 4 5 6;1 2 3; 3 2 4; 1 2 3; 3 2 1; 1 3 2] ;
row2check = 1;
repeated = 0 ;
for i = 1 : size(a,1)
repeated = repeated + prod(double([a(row2check,:)== a(i,:)])) ;
end
fprintf('\n Row number %i is reapeated %i times in matrix!\n\n',row2check,repeated);

その他の回答 (1 件)

Image Analyst
Image Analyst 2014 年 5 月 9 日
編集済み: Image Analyst 2014 年 5 月 9 日
Using ismember() is the usual method. Try this:
m = randi(9, [5000, 3]); % Create sample data.
% For demo, let's make sure row 9 is a repeat.
% In other words, row 9 is a duplicate of row 1.
m(9,:) = m(1,:);
% Let's see if row i is repeated
i = 1; % Could be any number up to size(m, 1);
% Use ismember to find repeated rows.
[lia, locb] = ismember(m, m(i,:), 'rows');
% locb is a logival vector. Find the actual row numbers.
repeatedRows = find(locb)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by