help-octave
[Top][All Lists]
Advanced

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

Re: array of strings?


From: Mike Miller
Subject: Re: array of strings?
Date: Fri, 13 Sep 2013 07:59:16 -0400

On Fri, Sep 13, 2013 at 00:19:49 -0700, MrOba wrote:
> I have no problems with a numeric matrix. I can save and load my data as
> mxArray.
> When I try with an array of string, if I create the matrix like matrix "a"
> in my previous post (# type: string and NOT dq_string ) I can still save and
> load the binary data.
> When the matrix is of a different type (dq_string or sq_string) I still can
> save the data, but I cannot load it  in my C++ code ( k.contents
> (varName).matrix_value() results in an error:  invalid conversion from
> string to real matrix).
>
> I hope this clarify a bit.

Perfect, thanks for clarifying.

So the piece you are missing in this case is the parameter to force
conversion of strings to other types. Every one of the *_value methods
takes an optional bool that defaults to false, meaning to not coerce
the conversion you want in your case. If you don't pass true, you get
exactly the error you are seeing. Call matrix_value(true) and that
should work for you.

There is a comment in the code about special handling of the type
"string" for backwards-compatibility that may explain why that one
works without the need to force conversion.

-- 
mike


reply via email to

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