i have values such as A=[12 20 1 5 69 70 21 50 46 52 87 83 11 21]
B=[ 70 50 12 83]
now i want to delete B values from A ,so i will have output as
C=[20 1 5 69 21 46 52 87 11 21 ]

 Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 28 Feb. 2012

0 Stimmen

[C1,ic] = setdiff(A,B)
[i1,i1] = sort(ic)
C = C1(i1)
OR
C = A(~ismember(A,B))

Weitere Antworten (1)

Wayne King
Wayne King am 28 Feb. 2012

0 Stimmen

Hi, You can use intersect to get the indices of A that intersect with elements of B and then delete those.
[C,IA,IB] = intersect(A,B);
A(IA) = [];

3 Kommentare

kash
kash am 28 Feb. 2012
wayne thanks a lot ,without using any in built command is it possible,using loops
Oleg Komarov
Oleg Komarov am 28 Feb. 2012
Sounds like a homework.
Jan
Jan am 28 Feb. 2012
No, kask, it is impossible to do this "without built-in command", because all you can write in Matlab requires built-in commands. If your teacher told you to do this, ask him for thinking twice.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Audio I/O and Waveform Generation finden Sie in Hilfe-Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by