I would like a function to remove the duplicate values, but one that removes the duplicate value as well.

1 ビュー (過去 30 日間)
Clodoaldo de Souza Faria Júnior
Clodoaldo de Souza Faria Júnior 2021 年 9 月 23 日
コメント済み: Matt J 2021 年 9 月 24 日
I would like a function to remove the duplicate values, but one that removes the duplicate value as well.
That is, if I have a vector A = [ 1 2 3 4 5 6 6 6 7], I would like to get an output equal to B = [1 2 3 4 5 7].
Note that I want to get the same order as the original vector, I don't want it to organize.
That is, if I have a vector A = [7 8 9 6 5 2 2 2 1], in the end I would like to get a vector equal to B = [7 8 9 6 5 1].

採用された回答

Matt J
Matt J 2021 年 9 月 23 日
編集済み: Matt J 2021 年 9 月 23 日
USing the functions in
A = [7 8 9 6 5 2 2 2 1];
G=groupConsec(A);
[~,~,len]=groupLims(G,1);
L=len==1;
B=A(L(G))
B =
7 8 9 6 5 1
  2 件のコメント
Matt J
Matt J 2021 年 9 月 24 日
Even easier:
A = [7 2 8 9 6 5 2 1 2];
G=findgroups(A);
L=accumarray(G(:),1)==1;
B=A(L(G))
B = 1×6
7 8 9 6 5 1

サインインしてコメントする。

その他の回答 (0 件)

タグ

製品


リリース

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by