[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: varargout{:} = func() ?
From: |
Ben Abbott |
Subject: |
Re: varargout{:} = func() ? |
Date: |
Tue, 23 Feb 2010 21:57:45 -0500 |
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
Re: varargout{:} = func() ?, Jaroslav Hajek, 2010/02/23