Azzera filtri
Azzera filtri

matrix ismember of another matrix

3 visualizzazioni (ultimi 30 giorni)
alex
alex il 17 Mar 2014
Commentato: alex il 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!

Risposta accettata

per isakson
per isakson il 17 Mar 2014
Modificato: per isakson il 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 Commenti
alex
alex il 17 Mar 2014
thank you very much!
alex
alex il 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?

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by