octave-maintainers
[Top][All Lists]
Advanced

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

Re: determining number of matrices passed to function


From: Przemek Klosowski
Subject: Re: determining number of matrices passed to function
Date: Tue, 12 Feb 2002 13:43:09 -0600


   I make fairly frequent use of what MATLAB knows as 'cell arrays'. For 
   example, suppose I have 2 matrices: A and B. I can put them into a cell 
   array (called MAT) using

   MAT={A;B};

   I can then pass MAT to a function, where I can use the length command to 
   determine the number of matrices in the cell array. In this example, 
   length(MAT) yields 2.

   However, this doesn't seem to work in Octave. If I try

Yeah, cell support in Octave is weak. Octave has lists that do basically
the same.  

    octave:6> a=[1 2 ; 3 45]; b=[1 2 ; 3 99]; c=[1 2 ; 3 4]; 
    octave:7> d=list (a,b,c)
    d =     (
      [1] = ...
      [2] = ...
      [3] = ...
    )
    octave:8> length(d)
    ans = 3
    octave:9> nth(d,1)
    ans =
      1  2
      3  45

One thing that lists don't do that Matlab cells do is that you
can apparently wrap multiple arguments into a cell, transparently,
i.e. in matlab fun(a,b,c) is equivalent to d={a,b,c}, fun(d).

I'd actually prefer passing arguments via structures, like so:

        function t=fff(x,y,z);t=x*y*z;endfunction
        arg.x= <some array>; arg.y=<other array>; arg.z=1;
        fff(arg)

For this to be really nice, one would need anonymous arrays in
octave, a la Perl's initialization:

        fff( (x => 5; y => [12,10]; z => 1) )

i.e. the formal arguments are passed in structure members with a
corresponding name.  The advantage over Matlab's way would be
positional/order independence. What do people think about this?



reply via email to

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