help-octave
[Top][All Lists]
Advanced

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

Re: varargout{:} = func() ?


From: Jaroslav Hajek
Subject: Re: varargout{:} = func() ?
Date: Wed, 24 Feb 2010 06:01:06 +0100

On Wed, Feb 24, 2010 at 3:47 AM, FW <address@hidden> wrote:
>> v =
>>     []
>>     []
>>     []
>>
>>>> v{:} = rand(1,2)
>> v =    [1x2 double]
>>
>> My impression is that this isn't very new, but as I've always found some of 
>> how Matlab handles cells to be counter intuitive (if not misleading), so I'm 
>> not in the habit of using this notation.
>
> Do you have a way of returning a cell array of results that packages
> up the variable outputs?  That is the reasonable problem this notation
> solves, even if the syntax is not so reasonable.
>

 v = cell (expected_nargout, 1);
 [v{:}] = func (...);

it's necessary to pre-allocate the cell array because in the second
line, the number of output values (nargout) should be determined
before func () is called. That is why [v{:}] doesn't work if v doesn't
exist.

If you have something else on mind, then please clarify.

-- 
RNDr. Jaroslav Hajek, PhD
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz



reply via email to

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