matching unequal arrays

Hi; I want to match the values of unequal arrays for a case as
m=(1:6); n=[1 2 5];
output=(0 0 1 1 0 1)
that is if an element of n is in m then the value in output is zero else 1.
Any hints?

 Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 8 de En. de 2012

0 votos

output = ~ismember(m,n)

3 comentarios

Sara
Sara el 9 de En. de 2012
if n is 2x3 whereas m is 1x6 is it still possible to assign the values in row 2 of n to output
say n=[1 2 5; 2 3 4];
output is then [0 0 1 1 0 1; 0 0 2 3 0 4]
Andrei Bobrov
Andrei Bobrov el 9 de En. de 2012
n=[1 2 5; 2 3 4];
m = 1:6;
output = zeros(size(m) + [1 0]);
t = ~ismember(m,n(1,:));
output(1,:) = t;
output(2,t) = n(2,:)
Sara
Sara el 10 de En. de 2012
When I use the code on arrays of different size for instance m=1x1502 and n=2x866 there will be a mismatch in the last row of the code, obviously the size at the left and right of the array is not equal. Would n(2,: ) be expanded to the appropriate size without using loops?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Operators and Elementary Operations en Centro de ayuda y File Exchange.

Preguntada:

el 8 de En. de 2012

Community Treasure Hunt

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

Start Hunting!

Translated by