[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Second output argument for setdiff
From: |
John W. Eaton |
Subject: |
Second output argument for setdiff |
Date: |
Tue, 15 Apr 2008 16:33:40 -0400 |
On 15-Apr-2008, Marco Caliari wrote:
| 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.
Would someone please turn this into a patch that includes tests?
Thanks,
jwe