octave-maintainers
[Top][All Lists]
Advanced

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

returning a cell array in a octave_value_list ?


From: John W. Eaton
Subject: returning a cell array in a octave_value_list ?
Date: Fri, 23 Mar 2012 09:19:04 -0400

On 23-Mar-2012, CdeMills wrote:

| I tried to find inspiration in strfind.cc.
| 
| - the output argument is defined as octave_value retval;
| if the first arg is a string, the code is
|   retval = octave_value (Array<octave_idx_type>)
| if the first arg is a cell array, a new variable retc is defined as a Cell
| with the same size as this arg
| then it iterate as
|      retc(i) = octave_value  (Array<octave_idx_type>)
| and finally 
|     retval = retc;
| 
| So the output is polymorphic: either an array of indexes, either a cell
| array of array of indexes

All DLD_FUNCTIONS return octave_value_list objects, but there is an
octave_value_list constructor that can be used to convert an
octave_value object to an octave_value_list object that contains a
single element.

If you need to assign multiple values, you need to do it with
something like


  octave_value_list retval;

  retval(1) = thing_1;
  retval(0) = thing_0;

octave_value_list resizes automatically, so assigning in reverse order
ensures that the resizing only happens once.

Or, you can explicitly set the size and assign in any order:

  retval.resize (2);

  retval(0) = thing_0;
  retval(1) = thing_1;

jwe


reply via email to

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