Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

setdiff keeping repetitions

102 views
Skip to first unread message

gianni

unread,
Oct 27, 2005, 5:51:50 AM10/27/05
to
% anyone with a trick to keep the repetitions with setdiff function ?
thank you for tricks

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

Jos

unread,
Oct 27, 2005, 5:59:20 AM10/27/05
to

tf = ~ismember(A,B,'rows') ;
C = A(tf,:) ;
ir = find(tf) ;

hth
Jos

Gianni

unread,
Oct 27, 2005, 10:49:49 AM10/27/05
to
Jos wrote:
> 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

John D'Errico

unread,
Oct 27, 2005, 1:44:36 PM10/27/05
to
In article <ef19...@webx.raydaftYaTP>,
Gianni <sch...@univ.trieste.it> wrote:

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

0 new messages