octave-maintainers
[Top][All Lists]
Advanced

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

Re: request test in Matlab, cellfun and anonymous functions with > 1 out


From: Ben Abbott
Subject: Re: request test in Matlab, cellfun and anonymous functions with > 1 outputs
Date: Wed, 23 Jul 2014 05:15:09 -0400

On Jul 23, 2014, at 4:58 AM, Julien Bect <address@hidden> wrote:

> Le 23/07/2014 10:36, Olaf Till a écrit :
>> Could someone test these lines in Matlab?
>> 
>> octave:1> [a, b] = cellfun (@ (x) {x, x}{:}, {1})
>> error: cellfun: function returned fewer than nargout values
>> 
>> and
>> 
>> octave:1> a = @ (x) {x, x}{:}
>> a =
>> 
>> @(x) {x, x} {:}
> 
> >> [a, b] = cellfun (@ (x) {x, x}{:}, {1})
> [a, b] = cellfun (@ (x) {x, x}{:}, {1})
>                              |
> Error: Unbalanced or unexpected parenthesis or bracket.
> 
> >> a = @ (x) {x, x}{:}
> a = @ (x) {x, x}{:}
>                |
> Error: Unbalanced or unexpected parenthesis or bracket.
> 
> 
> (in Matlab R2012a)
> 

Matlab chokes on statements like below.

  {1, 2}{:}
        |
Error: Unbalanced or unexpected parenthesis or bracket.

Adding the extra step of variable assignment gives the desired result, but will 
not work in an inline function.

a = {1,2};
[b{1:2}] = a{:}

b = 

    [1]    [2]

The deal() function may be used to allow an inline function to return multiple 
outputs.

An implementation of the original cellfun() is below.

        [a, b] = cellfun (@ (x) deal (x, x), {1})

Ben




reply via email to

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