"i am not able to understand this"
Your code:
first creates a logical array with the same size as codes, with 1 in every location where the arrays differ (you can see that the second row is all zero, where the data match exactly):
>> codes~=s
ans =
0 0 1 1 0 0 1 1 1 1 0 0 1 1 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 0 1 0 1 0 1 1 0 1 0 1 0 1 0
You then use find to obtain the linear indices of those 1's. From the above matrix it is clear that the linear indices will be [6,7,10,12,...], but this is easy to check using MATLAB too:
>> find(codes~=s)
ans =
6
7
10
12
18
19
22
24
25
27
28
33
37
39
40
45
You then use these linear indices to select elements from codes, you can check this yourself too:
codes(6) = 0
codes(7) = 1
codes(10) = 1
codes(11) = 1
codes(12) = 1
...
codes(40) = 0
codes(45) = 1
and that is your output vector. Interesting, but ultimately not very useful for the task you described.
"how to match and eliminate those values??"
So far two people have advised to use setdiff: why are you not doing this?
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
Best Answer