フィルターのクリア

How to remove duplicate element from matrix ?

1 回表示 (過去 30 日間)
Arshub
Arshub 2021 年 12 月 30 日
コメント済み: Voss 2022 年 1 月 1 日
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);
  1 件のコメント
Image Analyst
Image Analyst 2021 年 12 月 30 日
That's not a matrix. That's a vector.

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

採用された回答

Voss
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]
S = 1×16
1 11 1 4 3 14 6 11 13 11 7 15 5 9 9 7
[C,i] = unique(S,'stable')
C = 1×11
1 11 4 3 14 6 13 7 15 5 9
i = 11×1
1 2 4 5 6 7 9 11 12 13
C = [C S(~ismember(1:numel(S),i))]
C = 1×16
1 11 4 3 14 6 13 7 15 5 9 1 11 11 9 7
  3 件のコメント
Arshub
Arshub 2021 年 12 月 31 日
編集済み: Arshub 2021 年 12 月 31 日
@Benjamin can you help me in this state:
I need to use C=[1 3 4 5 6 7 9 11 13 14 15 1 7 9 11 11]
as index to perform permutation of matrix A =[111 222 30 4;50 65 70 83; 10 27 39 40 ; 54 67 72 81 ] by this method:
Substitute A(Ci ) with A (CM×N−i+1).
here i = 1, 2,..., M × N/2.
then i need to make reverse operartion to get the original matrix.
I write the code but when I make reverse operation I coulden't get the original matrix "M" after permutation, Why?
What should I do to get original matrix from permutated matrix?
Note: it is immportant to me use "Substitute A(Ci ) with A (CM×N−i+1)."
to permutate matrix.
%-----------------------------------------------------my rest of code ---------------------------------
A =[111 222 30 4;50 65 70 83; 10 27 39 40 ; 54 67 72 81 ];
[row,col]=size(A);
len=row*col;
A=reshape(A,1,len);
for i =1:len/2
A(C(i))=A(C(len-i+1));% Substitute A(Ci ) with A (CM×N−i+1)., permutation matrix
end
Ab=reshape(A,row,col)
AA=reshape(Ab,1,len);
for i =1:len/2
AA(C(len-i+1))=AA(C(i));% reverse Substitute A (CM×N−i+1) with A(Ci ) to get original matrix
end
AA=reshape(AA,row,col)
Voss
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 ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by