Effacer les filtres
Effacer les filtres

matrix ismember of another matrix

2 vues (au cours des 30 derniers jours)
alex
alex le 17 Mar 2014
Commenté : alex le 17 Mar 2014
hello!
i have
A=[1 2 3 4 5]
B=[2 4]
i want to create D=[1 3 5], which is the A without the elements of B
j=1;
A=[1 2 3 4 5];
B=[2 4];
C=ismember(A,B);
for i=1:5
if C(i)==0
A(j)=A(i);
j=j+1;
end
end
for i=1:3
D(i)=A(i);
end
the code above works fine,but i want to know if there is any other way to do this,for any matrices with any dimentions
Thank you very much!

Réponse acceptée

per isakson
per isakson le 17 Mar 2014
Modifié(e) : per isakson le 17 Mar 2014
A=[1 2 3 4 5];
B=[2 4];
C = setdiff( A, B )
returns
C =
1 3 5
Not sorted:
C = setdiff( A, B, 'stable' );
.
This works with vectors, however, "any matrices with any dimentions" is a different story
  2 commentaires
alex
alex le 17 Mar 2014
thank you very much!
alex
alex le 17 Mar 2014
i have a problem here
A = 2:.1:15
B=[9.4000 10.4000]
C=setdiff(A,B)
the elements 9.4000 and 10.4000 are in the C
however,if B=[9.3000 10.3000] then the setdiff works fine.
any idea why this happens?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

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

Community Treasure Hunt

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

Start Hunting!

Translated by