MATLAB: call to java.lang.String

It seems like I'm stuck on Kafka, with java.lang.String, which I cannot 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 converting from char to opaque: Error using ==> horzcat Undefined function or method 'opaque' for input arguments of type 'char'. 

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

+6
java string matlab
source share
4 answers

Matlab does not know how to work with anything other than its own structures.

Convert string to char:

cName = char(name);

+12
source share

I don’t think I understood this, you should explicitly use the char() method:

 K>> ['my name is ' char(name)] ans = my name is Jason 
+4
source share

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

 cName = name.toCharArray()' 

Will return an array of MATLAB characters.

+3
source share

str2mat(name) worked for me.

0
source share

All Articles