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?

 Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 8 Jan. 2012

0 Stimmen

output = ~ismember(m,n)

3 Kommentare

Sara
Sara am 9 Jan. 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 am 9 Jan. 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 am 10 Jan. 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?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Operators and Elementary Operations finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by