0

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.

2 Answers 2

1

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.

There is no need for a system command with Java code in MATLAB. You have direct access to the JVM from inside MATLAB. For an application with a complex GUI, break out to Java.

Undocumented Java is a valuable source on MATLAB, Java and GUIs.

Sign up to request clarification or add additional context in comments.

Comments

0

Yes the classpath set is correct.

I modified the code, using it without main..

class HelloWorld
{
        public String Hello()
        {
            String helloWorld="Hello World!";
            return helloWorld;
        }
}

Now, as per guided i try to create instance obj in Matlab, with following command:

o = HelloWorld;

Here I get following err:

??? No constructor 'HelloWorld' with matching signature found.

The next command indicated it this:

output = o.hello;

which wouldnt work unless instance is created.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.