varargout{:} = func() ?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

varargout{:} = func() ?

forkandwait
Has this notation been implemented in octave yet?

Tx

_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: varargout{:} = func() ?

bpabbott
Administrator
On Feb 23, 2010, at 7:43 PM, WS wrote:

> Has this notation been implemented in octave yet?
>
> Tx

hmmm ... if you mean something like what is below, then yes.

function varargout = foobar ( )
  for n = 1:numel(nargout)
    varargout{n} = n;
  end
end

In this instance "varargout" has a special meaning.

If you mean, something like what is below, then that doesn't work with 3.2.x, but does with Matlab.

        v{:} = {rand(1,2), rand(1,3)}
        error: invalid dimension inquiry of a non-existent value

or

        v{:} = rand(1,2)
        error: invalid dimension inquiry of a non-existent value

Jarsolav, is this something that should be added to Octave?

Ben

_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: varargout{:} = func() ?

John W. Eaton
Administrator
On 23-Feb-2010, Ben Abbott wrote:

| On Feb 23, 2010, at 7:43 PM, WS wrote:
|
| > Has this notation been implemented in octave yet?
| >
| > Tx
|
| hmmm ... if you mean something like what is below, then yes.
|
| function varargout = foobar ( )
|   for n = 1:numel(nargout)
|     varargout{n} = n;
|   end
| end
|
| In this instance "varargout" has a special meaning.
|
| If you mean, something like what is below, then that doesn't work with 3.2.x, but does with Matlab.
|
| v{:} = {rand(1,2), rand(1,3)}
| error: invalid dimension inquiry of a non-existent value
|
| or
|
| v{:} = rand(1,2)
| error: invalid dimension inquiry of a non-existent value
|
| Jarsolav, is this something that should be added to Octave?

You need to write

  v = cell (expected_nargout, 1);

  [v{:}] = func (...);

Does

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

work in Matlab?  If so, I think that's a relatively new addition and
in my opinion doesn't really fit with the rest of the language.

jwe
_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: varargout{:} = func() ?

bpabbott
Administrator
On Feb 23, 2010, at 8:11 PM, John W. Eaton wrote:

> On 23-Feb-2010, Ben Abbott wrote:
>
> | On Feb 23, 2010, at 7:43 PM, WS wrote:
> |
> | > Has this notation been implemented in octave yet?
> | >
> | > Tx
> |
> | hmmm ... if you mean something like what is below, then yes.
> |
> | function varargout = foobar ( )
> |   for n = 1:numel(nargout)
> |     varargout{n} = n;
> |   end
> | end
> |
> | In this instance "varargout" has a special meaning.
> |
> | If you mean, something like what is below, then that doesn't work with 3.2.x, but does with Matlab.
> |
> | v{:} = {rand(1,2), rand(1,3)}
> | error: invalid dimension inquiry of a non-existent value
> |
> | or
> |
> | v{:} = rand(1,2)
> | error: invalid dimension inquiry of a non-existent value
> |
> | Jarsolav, is this something that should be added to Octave?
>
> You need to write
>
>  v = cell (expected_nargout, 1);
>
>  [v{:}] = func (...);
>
> Does
>
>  v = cell (expected_nargout, 1);
>  v{:} = func (...);
>
> work in Matlab?  If so, I think that's a relatively new addition and
> in my opinion doesn't really fit with the rest of the language.

>> v = cell (3, 1)
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.

Ben

_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave