help-octave
[Top][All Lists]
Advanced

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

Re: Convert double to octave_value for assignment to column vector


From: David Grundberg
Subject: Re: Convert double to octave_value for assignment to column vector
Date: Wed, 02 Jun 2010 14:01:25 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.9) Gecko/20100317 Thunderbird/3.0.4

On 06/02/2010 02:26 AM, babelproofreader wrote:

I want to allocate the result of a feval function call to a column vector in
the code below

#include<octave/oct.h>
#include<octave/dColVector.h>
#include<octave/parse.h>

DEFUN_DLD (rm_compile_1, args, , "Input is a column vector, output is median
vector. This is a test of compiling Octave median function")
{
octave_value_list retval;

  ColumnVector rm_compile_1_input = args(0).column_vector_value ();
  ColumnVector rm_compile_1_output = args(0).column_vector_value ();
  octave_value input_median; // declare an octave value to hold output of
feval call to Octave median function

  input_median = feval ( "median", octave_value (rm_compile_1_input) );

  for (octave_idx_type ii (0); ii<  args(0).length (); ii++) // loop to fill
output vector with median value
      {
      rm_compile_1_output(ii) = input_median;
      }

retval = rm_compile_1_output;

return retval;
}

but on compiling there is an error message
rm_compile_1.cc:17: error: cannot convert ‘octave_value’ to ‘double’ in
assignment

How do I convert the returned value from the feval call to an octave type
that can then be assigned to the column vector in the loop?


I don't think you can assign an octave_value to a ColumnVector. It wants double elements.

Simply call the correct octave_value method to return the value as a double. I don't remember the name but it's in ov.h. Maybe input_median.as_double ()?

David


reply via email to

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