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)
d = 1×0 empty double row vector

Iniciar sesión para comentar.

Respuestas (1)

Categorías

Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 9 de Mayo de 2022

Comentada:

el 9 de Mayo de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by