how to passs output of Java program to m-file

Hello folks,
I have written a Java program which is invoked using system() function, thus it runs on the command window of Matlab. Now I want to know if there's another way to run a Java program other than running it on command window? Can it be run on any user made GUI in Matlab? Another problem is, I want to know if my program has some string value as output, which is generally displayed on command window, how can i store it in variable in Matlab?
Hope to hear from you very soon.

Answers (1)

5 Comments

Thank u Kaustubha.
all help that is available deals with Matlab language using Java objects. My trouble is to directly use java class in Matlab.
I have followed pre requisites, have added root directory to classpath and set all required environment variables. But I don't know how to call my java program or .class file.
Plus, there's question of how to handle data returned from this program.
Hope to hear from u very soon.
U can also contact me directly @ neha.revari@gmail.com
Richard has an example usage on http://www.mathworks.com/matlabcentral/answers/6923-calling-a-java-class-from-matlab
Once you have added your Java class directory to the classpath, simple instantiate that class in MATLAB.
Hey Kautubha,
I have this query I'm troubling since long with it.
I need to invoke a java class in Matlab, and need to store the returned string value in a variable in Mtalab. for this query i got following solution from a website, plz tell me where its going wrong:
>>
The Hello World solution by The MathWorks provides some insights on how to run a simple 'Hello World' java application inside MATLAB. You may change the Java code a bit, in order to have a method that returns a String.
public class HelloWorld
{
public String hello()
{
String helloWorld = "Hello World!";
return helloWorld;
}
}
Once this simple class is compiled and on the MATLAB JVM classpath create an instance and invoke the method with the following two commands.
o = HelloWorld
output = o.hello;
The String returned by the HelloWorld instance is assigned to the MATLAB variable output.
<<
The command described to invoke java code in matlab(ie o=HelloWorld) gives error.
What is the error that you see?
Hello, im currently having the same issue as the above fellow. I use the command javaaddpath, with the path to the .class file which i want to call a method from, and it gives me the following error
>> javaaddpath('C:\testeTobii\bin\tobii\Tobii.class');
>> o = Tobii;
Unrecognized function or variable 'Tobii'.
I have already tried to insert the path on "classpath.txt" file and creating a java file "javaclasspath.txt" placing it inside the prefdir of Matlab.

Sign in to comment.

Categories

Find more on Construct and Work with Object Arrays in Help Center and File Exchange

Asked:

on 18 May 2011

Commented:

on 2 Mar 2021

Community Treasure Hunt

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

Start Hunting!