MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   整理清单 (https://www.labfans.com/bbs/showthread.php?t=23212)

poster 2019-12-10 20:30

整理清单
 
我相当确定(在MATLAB中)应该对此有一个优雅的解决方案,但是我现在想不出来。

我有一个带有[classIndex,start,end]的列表,我想将连续的类索引折叠成一组,如下所示:

这个

1 1 40 2 46 53 2 55 55 2 57 64 2 67 67 3 68 91 1 94 107 应该变成这个

1 1 40 2 46 67 3 68 91 1 94 107 我怎么做?

[B]编辑[/B]

没关系,我想我明白了-几乎就像[URL="https://stackoverflow.com/questions/2455050/tidying-up-a-list/2455143#2455143"]fmarc的解决方案一样[/URL] ,但是索引正确

a=[ 1 1 40 2 46 53 2 55 55 2 57 64 2 67 67 3 68 91 1 94 107]; d = diff(a(:,1)); startIdx = logical([1;d]); endIdx = logical([d;1]); b = [a(startIdx,1),a(startIdx,2),a(endIdx,3)];

[B]回答:[/B]

这是一种解决方案:

Ad = find([1; diff(A(:,1))]~=0); output = A(Ad,:); output(:,3) = A([Ad(2:end)-1; Ad(end)],3); clear Ad

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


所有时间均为北京时间。现在的时间是 05:08

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