poster
2019-12-14, 20:46
我有4892行和4列的双打矩阵。
假设在第3列和第4列中有N行具有相同的值(但不一定在第1列和第2列中),我只想在组中保留一行。
一个例子:
1738 1738 8611 8611
1739 1738 8611 8611
1739 1739 8611 8611
我只想在这一排中只留下一行(与哪一行无关)。
我该怎么做呢?
谢谢!
回答:
使用UNIQUE (http://www.mathworks.com/help/techdoc/ref/unique.html) 。默认情况下,这将保留最后一行。
%# array is your 4892-by-4 array %# call 'unique(array(:,3:4),'rows','first') if you want to keep the first row [~,idx] = unique(array(:,3:4),'rows'); %# use sort if you want to preserve the original order of rows trimmedArray = array(sort(idx),:);
更多&回答... (https://stackoverflow.com/questions/5407848)
假设在第3列和第4列中有N行具有相同的值(但不一定在第1列和第2列中),我只想在组中保留一行。
一个例子:
1738 1738 8611 8611
1739 1738 8611 8611
1739 1739 8611 8611
我只想在这一排中只留下一行(与哪一行无关)。
我该怎么做呢?
谢谢!
回答:
使用UNIQUE (http://www.mathworks.com/help/techdoc/ref/unique.html) 。默认情况下,这将保留最后一行。
%# array is your 4892-by-4 array %# call 'unique(array(:,3:4),'rows','first') if you want to keep the first row [~,idx] = unique(array(:,3:4),'rows'); %# use sort if you want to preserve the original order of rows trimmedArray = array(sort(idx),:);
更多&回答... (https://stackoverflow.com/questions/5407848)