[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Is there a way to let @ defined function handle return multiple valu
From: |
Juan Pablo Carbajal |
Subject: |
Re: Is there a way to let @ defined function handle return multiple values? |
Date: |
Mon, 1 Jul 2013 12:25:29 +0200 |
On Mon, Jul 1, 2013 at 7:32 AM, Ben Abbott <address@hidden> wrote:
> On Jun 30, 2013, at 11:34 PM, Peng Yu <address@hidden> wrote:
>
> Hi,
>
> http://www.gnu.org/software/octave/doc/interpreter/Function-Handles.html
>
> I only see @ can be used to define function handles with one return
> value. Is it possible to define a function handle to return two
> values? Thanks.
>
>
> I assume you're asking about in-line functions? For that, use deal(). A
> trivial example is below.
>
> fun = @(x,y) deal (x, y);
>
> [a, b] = fun (1, 2)
>
> a = 1
>
> b = 2
>
>
> Ben
>
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://mailman.cae.wisc.edu/listinfo/help-octave
>
All solutions given before are valid, you can also stick to the single
value and return a matrix/cell with the different values and deal them
afterwards.
Z =@(x) [x+1, x.^2];
x = [1; 2; 3];
X = Z(x);
xp1 = X(:,1);
x2 = X(:,2);