A command like "unique" for matrices?

2 vues (au cours des 30 derniers jours)
Amy Hs
Amy Hs le 23 Avr 2019
Commenté : Amy Hs le 23 Avr 2019
Hi guys,
Is there any command like "unique" for matrices?
I have a major matrice (mother) , and that involve few minor matrices, some of are repeated randomly
i'm looking for a command for delete repeated ones and do something like unique ,
anybody knows how?
  3 commentaires
Andrei Bobrov
Andrei Bobrov le 23 Avr 2019
Please post an example of your matrix and what you want to receive.
Amy Hs
Amy Hs le 23 Avr 2019
thanks for your reply
see,
we have 3 matrices,
A=[1;2;3] ; B=[1;2;3] ; C=[4;5;6];
all of them are in another matrice (call it R)
R={A;B;C}
as you see A & B 's first column are the same,
i want to delete one of them (A or B) and the result must be like below:
R={A;C}

Connectez-vous pour commenter.

Réponse acceptée

Stephen23
Stephen23 le 23 Avr 2019
Modifié(e) : Stephen23 le 23 Avr 2019
A general solution that does not concatenate the data and works for any size arrays:
% Fake data:
A = [1;2;3];
B = [1;2;3];
C = [4;5;6];
R = {A;B;C}
% Method:
N = numel(R);
X = false(1,N);
for ii=2:N
Y=false;
for jj=1:ii-1
Y = Y || isequal(R{ii},R{jj});
end
X(ii) = Y;
end
R(X) = []
  1 commentaire
Amy Hs
Amy Hs le 23 Avr 2019
thanks a lot

Connectez-vous pour commenter.

Plus de réponses (1)

Andrei Bobrov
Andrei Bobrov le 23 Avr 2019
A=[1;2;3];
C=[4;5;6];
M = [repmat(A,2,1);C];
out = reshape(unique(reshape(M,3,[])','rows','stable')',[],1);
  1 commentaire
Amy Hs
Amy Hs le 23 Avr 2019
thanks a lot

Connectez-vous pour commenter.

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Produits


Version

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by