簡體   English   中英

如何刪除Matlab矩陣中的某些行?

[英]how do i delete certain rows in a Matlab matrix?

我有4892行和4列的雙打矩陣。

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

一個例子:

1738 1738 8611 8611

1739 1738 8611 8611

1739 1739 8611 8611

我只想在這一排中只留下一行(與哪一行無關)。

我該怎么做呢?

謝謝!

使用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),:);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM