help-octave
[Top][All Lists]
Advanced

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

Re: size of 3d array


From: David Bateman
Subject: Re: size of 3d array
Date: Mon, 04 Dec 2006 13:01:56 +0100
User-agent: Thunderbird 1.5.0.7 (X11/20060921)

Norbert Hauser wrote:
> I haven't found the following difference between octave and matlab in the 
> compatibility list.
>
> The output of
>
> a=zeros(2,2,2);
> [s1,s2]=size(a)
>
> in octave is:
> s1 = 2
> s2 = 2
>
> and in matlab is:
> s1 =
>      2
> s2 =
>      4
>
> Is there an explanation, why matlab combines the dimensions 2+3 in s2, but 
> octave doesn't? Has this been implemented intentionally, and can I make 
> octave behave like matlab in this case without changing existing code?
>
> Despite of such small problems I am more and more impressed by octave's 
> capabilities Thanks to all who have contributed!
>
> Norbert
>   

The attached patch will make octave compatible with the behavior of
matlab. I don't know if I like the behavior of matlab, but if we want
compatibility this patch will do it.

D.

2006-12-04  David Bateman  <address@hidden>

        * data.cc (Fdata): If ndims is greater than nargout and
        nargout is greater than 1, then collect size of trailing
        dimensions into retval(end).


-- 
David Bateman                                address@hidden
Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph) 
Parc Les Algorithmes, Commune de St Aubin    +33 6 72 01 06 33 (Mob) 
91193 Gif-Sur-Yvette FRANCE                  +33 1 69 35 77 01 (Fax) 

The information contained in this communication has been classified as: 

[x] General Business Information 
[ ] Motorola Internal Use Only 
[ ] Motorola Confidential Proprietary

*** src/data.cc.~1.164.~        2006-11-22 19:55:07.000000000 +0100
--- src/data.cc 2006-12-04 12:55:50.188636317 +0100
***************
*** 1043,1048 ****
--- 1043,1058 ----
          for (int i = nargout-1; i >= ndims; i--)
            retval(i) = 1;
  
+         if (ndims > nargout)
+           {
+             octave_idx_type d = 1;
+ 
+             while (ndims >= nargout)
+               d *= dimensions(--ndims);
+             
+             retval(ndims) = d;
+           }
+ 
          while (ndims--)
            retval(ndims) = dimensions(ndims);
        }

reply via email to

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