find the repetition of matrix rows
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
更多回答(1 个)
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)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!