MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   如何与Matlab中的行进行比较 (https://www.labfans.com/bbs/showthread.php?t=26601)

poster 2019-12-14 20:13

如何与Matlab中的行进行比较
 
我有一个与此矩阵相似的矩阵:

1468 1468 1468 1711 1468 1469 1711 1468 1711 1711 1711 1469 1469 1468 1469 1711 1469 1469 并且我想在条目(j,i)存在的情况下删除条目(i,j)。例如,我想删除1711 1468因为1468 1711出现在其上方。

我该怎么做呢?



[B]回答:[/B]

假设删除行的顺序无关紧要,则可以将[URL="http://www.mathworks.com/help/techdoc/ref/sort.html"]SORT[/URL]和[URL="http://www.mathworks.com/help/techdoc/ref/unique.html"]UNIQUE[/URL]组合如下:

m = [1468 1468 1468 1711 1468 1469 1711 1468 1711 1711 1711 1469 1469 1468 1469 1711 1469 1469] [~,v]=unique(sort(m,2),'rows'); trimmedM = m(sort(v),:) %# keep the row ordering as in the original trimmedM = 1468 1468 1711 1468 1711 1711 1469 1468 1469 1711 1469 1469 请注意, unique将保留重复项的最后一个,这似乎符合您的要求。



[url=https://stackoverflow.com/questions/5313248]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 22:43

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.