A=[1 2 3 4 5 6 7 6 6 6 ]';
A=[A,ones(size(A,1),1)];
B=[ 1 2 3 4 5 7 9 12 13]';
B=[B,ones(size(B,1),1)];
[C,ir]=setdiff(A,B,'rows') % returns the rows from A that are not in
B.
% ... how to keep the repetitions?
....
C =
6 1
ir =
10
matlab output only the last occourence
... and if I want also the repetitions ?
i.e. ir= 6 8 9 10
tf = ~ismember(A,B,'rows') ;
C = A(tf,:) ;
ir = find(tf) ;
hth
Jos
Jos
thank you , it works fine !
one last question :
if I like to be more tollerant when comparing values in A to values
in B and declare that one is member ... say A(i) == B(j) even if they
differ by epsilon >0 ... can I temporarly redefine the precision
used by ismember ?
in simple words can I declare that 2 variables have the same value
(i.e. are member) even if they are only close one to the other ?
thank you
gianni
No, ismember uses exact comparisons. Even 1 bit
is enough to make two elements different.
Your best option is to round the two arrays, then
setdiff will work. You can use the trick I did in
writing consolidator, and round to a smaller
tolerance by scaling the arrays.
HTH
John D'Errico
--
The best material model of a cat is another, or preferably the same, cat.
A. Rosenblueth, Philosophy of Science, 1945
Those who can't laugh at themselves leave the job to others.
Anonymous