How to execute java program in MATLAB?

1 view (last 30 days)
Sanjay Saxena
Sanjay Saxena on 29 Jan 2015
Answered: David Young on 29 Jan 2015
Hello,
I am having MATLAB R2011a Version. I want to execute a java program using MATLAB. For this i have created a java program named as "Hello" and after compiling i converted into class file. Than i opened MATLAB set the class path by using edit classpath.txt. But wen i am executing this code using
o = Hello;
javaMethod('main', o);
it returns ??? Undefined function or variable 'Hello'. what to do?

Answers (1)

David Young
David Young on 29 Jan 2015
In
o = Hello;
Hello is the name of a variable, as it would be in Java also. (It could also be the name of a function in MATLAB.) When a variable name appears to the right of =, it is evaluated. Since Hello has not been given a value, the attempt to evaluate it fails and you see the error message.
You probably need
o = 'Hello';
The right hand side of this is a string constant, not a variable.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!