How to remove duplicate element from matrix ?
1 回表示 (過去 30 日間)
古いコメントを表示
I have duplicate matrix S, I need remove the repeated elements from S, and
then put the absent numbers at the end to generate a new matrix X. iI implement remove duplicate element but how we add absent element at the end?
S=[1 11 1 4 3 14 6 11 13 11 7 15 5 9 9 7];
C=unique(S);
採用された回答
Voss
2021 年 12 月 30 日
編集済み: Voss
2022 年 1 月 1 日
Here's one way:
S=[1 11 1 4 3 14 6 11 13 11 7 15 5 9 9 7]
[C,i] = unique(S,'stable')
C = [C S(~ismember(1:numel(S),i))]
3 件のコメント
Voss
2022 年 1 月 1 日
@Arshub I modifed my answer after seeing DGM's comment on your other question. I believe this answer is more what this question is looking for.
I recommend you update that other question to clarify the relationship between S and C, specifically that:
S=[1 11 1 4 3 14 6 11 13 11 7 15 5 9 9 7];
[C,i] = unique(S,'stable');
C = [C S(~ismember(1:numel(S),i))];
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!