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?

 採用された回答

Andrei Bobrov
Andrei Bobrov 2012 年 1 月 8 日

0 投票

output = ~ismember(m,n)

3 件のコメント

Sara
Sara 2012 年 1 月 9 日
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 2012 年 1 月 9 日
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 2012 年 1 月 10 日
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?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeOperators and Elementary Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by