## syntax to used unmatched values in matlab?

### Panda Girl (view profile)

on 7 Dec 2018
Latest activity Commented on by Jan

### Jan (view profile)

on 9 Dec 2018

c = [1,4,3]
sci = 1
a = sci;
findsamemember = ismember[c,a]
output will be
1 0 0
I am trying to get the values that are not matching with a in further process of the program. That is, the value that should be used as output in my next syntax is 4 and 3 (or at position 2 and 3)
How should I proceed with it?

### Tags

on 7 Dec 2018

idx=ismember(c,a); % idx is logical index
c(~idx)*4 %multiply with whatever number you wish

### Image Analyst (view profile)

on 7 Dec 2018

Simply use the function MEANT for this: setdiff():
c = [1,4,3]
sci = 1
a = sci;
[nonMatchingValues, nonMatchingIndexes] = setdiff(c, a)

Panda Girl

### Panda Girl (view profile)

on 8 Dec 2018
@Image Analyst My apologies if you got offended for not using your solutions. But, I am a begineer at matlab.. when you used setdiff in above example with matching and non matching indexes. I was not able to understand how should I use with my binary example. You might be an expert at this but everyone here is not... some people take time to understand and then implement your solutions.
Image Analyst

### Image Analyst (view profile)

on 8 Dec 2018
If you used my code,
c = [1,4,3]
sci = 1
a = sci;
[nonMatchingValues, nonMatchingIndexes] = setdiff(c, a)
You'll see that it produces:
nonMatchingValues =
3 4
nonMatchingIndexes =
3
2
which means that 3 doesn't match and is found at index 3, and 4 doesn't match and is found at index 2.
This is exactly what you said you wanted so all you had to do was copy and paste.
Note that the answer you accepted
idx=ismember(c,a); % idx is logical index
c(~idx)*4 %multiply with whatever number you wish
gives
ans =
16 12
which is not what you said you wanted. You did not want 16 and 12.
Now, for your next question, the approach I'd take is completely different
since both 0 and 1 appear in both of your arrays, so we can't use setdiff()
We need to use ismember instead, with the rows option. Using that
we can find out that row 2 is a match, and rows 1 and 3 do not match.
Here is the code:
s = [1 1 0 0 0 0 1 1 0 0 1 1 1 1 0 0]
codes = [...
1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0
1 1 0 0 0 0 1 1 0 0 1 1 1 1 0 0
1 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0]
matchingRows = ismember(codes, s, 'rows')
nonMatchingRows = find(~matchingRows)
You'll see that it produces:
matchingRows =
3×1 logical array
0
1
0
nonMatchingRows =
1
3
I think that is what you want, right? If so, copy it and try it. If not, explain better - we're still willing to help you.
Jan

### Jan (view profile)

on 9 Dec 2018
@Panda Girl: I've removed your flag. I suggest not to take the answers personally. Sometimes the very active members in internet forums behave, like they have answered a question a hundred times before, because they have answered it a hundred times before. It would be better, if all discussions are quite, calm and polite, but we are human.
I'm convinced, that Image Analyst was not offended by your question, and that you do not have to be offended, if he repeats to suggest using the alraedy provided solution. All he wants to do is to solve the problem.

### Stephen Cobeldick (view profile)

on 7 Dec 2018
Edited by Stephen Cobeldick

### Stephen Cobeldick (view profile)

on 7 Dec 2018

Method one: setdiff:
>> s = [1,1,0,0,0,0,1,1,0,0,1,1,1,1,0,0]
s =
1 1 0 0 0 0 1 1 0 0 1 1 1 1 0 0
>> c = [1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0;1,1,0,0,0,0,1,1,0,0,1,1,1,1,0,0;1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0]
c =
1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0
1 1 0 0 0 0 1 1 0 0 1 1 1 1 0 0
1 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0
>> z = setdiff(c,s,'rows')
z =
1 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0
1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0
Note that setdiff can change the order of the rows, unless you use the 'stable' option:
setdiff(c,s,'stable','rows')
Method two: indexing:
>> x = all(s==c,2);
>> z = c(~x,:)
z =
1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0
1 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0