octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Second output argument for setdiff


From: Marco Caliari
Subject: Second output argument for setdiff
Date: Tue, 15 Apr 2008 17:30:18 +0200 (CEST)

Dear maintainers,

first of all, my apologizes for not sending a hg patch.
The following code

[sorta,idxa] = sort(a);
idx = idxa(find(all(repmat(sorta(:)',size(c,1)*size(c,2),1)-...
      repmat(c(:),1,size(a,1)*size(a,2))) == 0));
[y,iy] = unique(a(idx));
i = reshape(idx(iy),size(c,1),length(idx(iy))/size(c,1));

put at the end of setdiff.m (Octave 3.0.1b) will return i such that c = a(i) (or c = a(i,:)). I checked the behaviour vs. Matlab with the following
script

clear all
disp('easy')
a = [10 20 30 40]
b = [20 40]
[c,i] = setdiff(a,b)
disp('unsorted')
a = [40 20 30 10]
b = [20 40]
[c,i] = setdiff(a,b)
disp('double entries')
a = [40 40 20 30 10]
b = [20 40]
[c,i] = setdiff(a,b)
disp('rows')
A = [10 20;30 40;50 60;30 40];
B = [10 20];
[C,I] = setdiff(A,B,'rows')

It would be nice to have this feature included in the next Octave release.

Best regards,

Marco


reply via email to

[Prev in Thread] Current Thread [Next in Thread]