removing repeats from lists
Mostrar comentarios más antiguos
Hi, I'm struggling to figure out an output list 'd' which has all elements that are in both lists 'a' and 'b', but not in list 'c' using below:
a=[3 5 1 8]
b=[1 5 2]
c=[5 1 4 2]
d=[ ]
but this code only works when removing 'b' from 'a' to make list 'c'.
a=[3 5 1 8];
b=[1 5 2]
n=length(a); m=length(b); c=[ ];
for j=1:n
flag = 0;
k=0;
while flag == 0 && k
k=k+1;
if a(j) == b(k)
flag = 1;
end;
end;
if flag == 0
c=[c a(j)];
end;
end;
c
1 comentario
Not many elements:
a = [3,5,1,8];
b = [1,5,2];
c = [5,1,4,2];
d = setdiff(intersect(a,b),c)
Respuestas (1)
David Hill
el 9 de Mayo de 2022
d=intersect(a,b);
d=d(~ismember(d,c));
Categorías
Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!