setdiff output differs from matlab
Jaroslav Hajek
highegg at gmail.com
Thu Sep 18 03:33:50 CDT 2008
On Wed, Sep 17, 2008 at 11:44 PM, John W. Eaton <jwe at bevo.che.wisc.edu> wrote:
> On 9-Sep-2008, Søren Hauberg wrote:
>
> | tir, 09 09 2008 kl. 13:07 -0500, skrev Michael Ferris:
> | > In octave: x = 1:5; y = setdiff(x,x); size(y)
> | > ans =
> | >
> | > 0 0
> | >
> | > In matlab: x = 1:5; y = setdiff(x,x); size(y)
> | > ans =
> | >
> | > 1 0
> |
> | Both produce empty matrices, it's only their size that differs.
>
> Yes, but if it makes sense to do so, I think we should try to make the
> sizes the same. What does Matlab return for each fo the following,
> and does it make sense, or does it just seem like an accident of the
> implementation, when it could just as easily return [] in all cases?
>
> x = 1:5;
>
> setdiff (x, x)
> setdiff (x', x)
> setdiff (x, x')
> setdiff (x', x')
>
> Thanks,
>
> jwe
>
>
> _______________________________________________
> Bug-octave mailing list
> Bug-octave at octave.org
> https://www-old.cae.wisc.edu/mailman/listinfo/bug-octave
>
Investigating further, I found out that it boils down to these differences:
1. a = 1:5; a(:) = []
--> a is 0-by-0 in both Octave and Matlab
2. a = 1:5; a(1:5) = []
--> a is 0-by-0 in Octave, 1-by-0 in Matlab
3. a = 1:5; a = a'; a(1:5) = []
--> a is 0-by-0 in Octave, 0-by-1 in Matlab
4. a = ones (3); a(:,:) = []
--> a is 0-by-0 in Octave, 0-by-3 in Matlab
IMHO we should fix cases 2 and 3. Unless anyone objects, I vote for
leaving 4, because Octave's behaviour seems more consistent given case
1. And anyway, 4 is probably very rare and unlikely to occur in real
code.
I'll try to submit a patch for these.
regards
--
RNDr. Jaroslav Hajek
computing expert
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz
More information about the Bug-octave
mailing list