[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Convert octave_value_list to RowVector
From: |
John W. Eaton |
Subject: |
Convert octave_value_list to RowVector |
Date: |
Wed, 24 Oct 2007 11:58:03 -0400 |
On 24-Oct-2007, John Swensen wrote:
| Is there a quick and easy way to convert an Octave value list to a
| RowVector? I have searched through the src and liboctave directories
| and can't find an example. For now, the only way I can figure out how
| to do it is
|
| RowVector rv;
| octave_value_list ovl;
|
| for ( int i = 0 ; i < ovl.length() ; i++ )
| rv(i) = ovl(i).matrix_value ()(0);
|
| There has got to be a better way. Any suggestions?
Is each element supposed to be a scalar? If so, why not
octave_idx_type len = ovl.length ();
RowVector rv (len);
octave_value_list ovl;
for (int i = 0; i < len; i++)
{
rv.xelem (i) = ovl(i).double_value ();
if (error_state)
break/return/whatever, but probably don't continue...
}
Note that a RowVector object is not resized automatically, so I think
you'd better give it a proper size before stuffing values in it. The
use of xelem instead of () avoids the reference count check which is
unnecessary here, but may be needed in your actual application.
jwe