如何删除Matlab矩阵中的某些行?

M.N*_*M.N 2 matlab matrix

我有一个带有4892行和4列的双打矩阵.

假设我在第3和第4列中有N行具有相同的值(但不一定在第1和第2列中),我想只留下一行中的一行.

一个例子:

1738 1738 8611 8611

1739 1738 8611 8611

1739 1739 8611 8611

我想在这一堆中只留下一行(无论哪一行).

我该怎么做呢?

谢谢!

Jon*_*nas 5

使用UNIQUE.默认情况下,这将保留最后一行.

%# 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),:);
Run Code Online (Sandbox Code Playgroud)