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 Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

질문:

2012년 1월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by