[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Changing data type in octave_value_list
From: |
Søren Hauberg |
Subject: |
Re: Changing data type in octave_value_list |
Date: |
Fri, 11 Aug 2006 21:07:56 +0200 |
Hi,
I'm not exactly sure if the following solve your problem, but it's
worth a shot:
#include <octave/oct.h>
#include <cstdlib>
DEFUN_DLD(bla, args, nargout, "...")
{
if (args(0).is_string()) {
args(0) = octave_value( atof(args(0).string_value().c_str()) );
}
return args;
}
I didn't have convert_s2i, so I converted to a double instead. The real
change is the use of the 'octave_value' constructor. Basicly you have to
insert 'octave_value's in an octave_value_list.
Hope it helps,
Søren
fre, 11 08 2006 kl. 12:52 -0600, skrev Joshua Rigler:
> This might be more of a C/C++ question, so please be kind...
>
> I am writing a .oct file, and the source includes the following standard
> definition at the beginning:
>
> DEFUN_DLD (cdflib, args, nargout, "...whatever...")
>
> As I understand things, 'args' is my input list, passed from the
> interpreter, and of type octave_value_list. I want to be able to pass
> one of my inputs as either a scalar, or a string that I can then
> convert/map to a corresponding scalar and place back into the same
> position in args, before proceeding to subsequent operations.
>
> What I naively thought I could do is (paraphrased):
>
> if (args(0).is_string)
> {
> args(0) = double (convert_s2i(args(0).string_value) );
> }
>
> ...where 'convert_s2i' is just a function that maps certain strings to
> long integers, which I am then happy to store as double-floats, since
> this is what Octave expects (I suppose newer versions have support for
> additional data types, including integers, but I'm perfectly happy with
> doubles). Note, I am not simply trying to convert an ascii '1' into its
> scalar equivalent, but rather a multi-character string that associates
> with a particular integer inside a C++ map object.
>
> Anyway, the problem I face is that I keep getting the following error:
>
> error: invalid conversion from string to real scalar
>
> I assume this corresponds to my attempt to transform args(0) from a
> string into a scalar. Is there a straight-forward way to do this?
> Thanks.
>
> -EJR
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://www.cae.wisc.edu/mailman/listinfo/help-octave
>
>