[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:07:38 +0100 |
On Wed, Feb 24, 2010 at 3:57 AM, Ben Abbott <address@hidden> wrote:
>
> On Feb 23, 2010, at 9:47 PM, FW 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.
>
> Beyond a single output ...
>
> v = {rand(1,2)}
>
> I expected the attempts below to work, but they did not.
>
> octave:5> function foobar(n)
>> end
> octave:6> function varargout = foobar(n)
>> for m = 1:n
>> varargout{m} = m;
>> end
>> end
> octave:7> v = {foobar(3)}
> v =
>
> {
> [1,1] = 1
> }
>
> octave:8> function [a,b,c] = foobar()
>> a = 1;
>> b = 2;
>> c = 3;
>> end
> octave:9> v = {foobar()}
> v =
>
> {
> [1,1] = 1
> }
>
> I should mention that I'm presently unable to run the developers sources, so
> I'm running 3.2.x.
>
> Ben
>
I think this is OK, because in all cases foobar is called with nargout
= 1. Excess output arguments are ignored.
Or does Matlab do something different?
--
RNDr. Jaroslav Hajek, PhD
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz
Re: varargout{:} = func() ?, Jaroslav Hajek, 2010/02/23
- Re: varargout{:} = func() ?, forkandwait, 2010/02/24
- Re: varargout{:} = func() ?, John W. Eaton, 2010/02/24
- Re: varargout{:} = func() ?, forkandwait, 2010/02/24
- Re: varargout{:} = func() ?, John W. Eaton, 2010/02/24
- Re: varargout{:} = func() ?, forkandwait, 2010/02/24