开发者

MATLAB: dealing with java.lang.String

I seem to be stuck in Kafka-land, with a java.lang.String that I can't seem to use in MATLAB functions:

K>> name

name =

Jason

K>> sprintf('%s', name)
??? Error using ==> sprintf
Function is not defined for 'java.lang.String' inputs.

K>> ['my name is ' name]
??? Error using ==> horzcat
The following error occurred conver开发者_开发技巧ting from char to opaque:
Error using ==> horzcat
Undefined function or method 'opaque' for input arguments of type 'char'.

how can I get a java.lang.String to convert to a regular MATLAB character array?


Matlab doesn't know how to work with anything but it's own structures.

Convert the string to a char:

cName = char(name);


As an alternative to using char() you can also use the java string methods. So

cName = name.toCharArray()'

Will return a MATLAB character array.


never mind, I figured it out, you have to use the char() method explicitly:

K>> ['my name is ' char(name)]

ans =

my name is Jason


str2mat(name) worked for me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜