help-octave
[Top][All Lists]

## Re: Variable number of function return values

 From: John W. Eaton Subject: Re: Variable number of function return values Date: Wed, 7 Jun 2006 14:29:01 -0400

```On  2-Jun-2006, David Bateman wrote:

| Gregor Beck wrote:
|
| > I try to get a variable number of return values from a function.
| > With matlab something like this does the trick:
| >
| > C = cell(1, 4);
| > [C{:}] = fileparts('work/mytests/strArrays.mat')
| >
| > C =
| > 'work/mytests' 'strArrays' '.mat' ''
| >
| > But with octave (2.9.5 & 2.1.44) I get
| >
| > C =
| > {
| >   [1,1] = work/mytests
| >   [1,2] = work/mytests
| >   [1,3] = work/mytests
| >   [1,4] = work/mytests
| > }
| >
| > Is this the intended behavior?
| > Is there another way to achieve this?
|
| This one has been on the TODO list for at least 4 years.

I've checked in a partial implementation of this feature (at long
last, progress!).  The following kinds of things work:

x = cell (1, 2);
[a, x{:}, b] = deal (1, 2, 3, 4);
[a, x{1:4}, b] = deal (1, 2, 3, 4, 5, 6);
[y.z{1:3}] = deal (1, 2, 3);

but these do not:

[x{1:2,1:2}] = deal (1, 2, 3, 4);

x(3).a = [];
[x.a] = deal (1, 2, 3);

I don't have immediate plans to work on these additional features, so
if someone else is interested, please let me know.  I can send you the
diffs for my changes if it would help you get started (it is less than
500 lines of diff -u output).

The last time I looked at this problem, I thought it would require
changes to the interface for the subsasgn method in the octave_value
class hierarchy, but I found another way to do it that doesn't require
interface changes, so this feature should not force any changes on
user-defined types.

jwe

```

reply via email to