Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Calling Java Main Method from Matlab

Subject: Calling Java Main Method from Matlab

From: Grant

Date: 10 Mar, 2010 16:55:21

Message: 1 of 2

Can anyone tell me how to call a Java class main method, that takes in a command line input string, from Matlab. My simple class looks something like this:

public class Calculate_square
  public static void main (String[] args){
    int input, output;
    input=args[0];
    output=input*input;
    System.out.println(output);
  }
}

I call this class from the terminal like this:

$java Calculate_square 4

Thank you

Subject: Calling Java Main Method from Matlab

From: Yair Altman

Date: 11 Mar, 2010 07:14:08

Message: 2 of 2

"Grant " <grant.clark@mcgill.ca> wrote in message <hn8itp$b2j$1@fred.mathworks.com>...
> Can anyone tell me how to call a Java class main method, that takes in a command line input string, from Matlab. My simple class looks something like this:
>
> public class Calculate_square
> public static void main (String[] args){
> int input, output;
> input=args[0];
> output=input*input;
> System.out.println(output);
> }
> }
>
> I call this class from the terminal like this:
>
> $java Calculate_square 4
>
> Thank you


did you try to simply call Calculate_square.main(...) from the Matlab command prompt?

Note that your class, as-is, will not work - you need to convert from String to int before you can multiply...

Yair Altman
http://UndocumentedMatlab.com

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us