### MATLAB Engine for Java

This library uses the C API of the MATLAB Engine to:

- put variables from Java to Matlab
- evaluate Matlab commands
- get results from Matlab to Java

http://mat4j.sourceforge.net/

#### Simple Example

This Java code:

```
MatlabEngine matlabEngine = new MatlabEngine();
matlabEngine.open(null);
matlabEngine.eval("x = sin([0:pi/2:2*pi])");
System.out.println(matlabEngine.getOutput());
DoubleMatrix doubleMatrix = (DoubleMatrix)matlabEngine.getVariable("x");
System.out.println("doubleMatrix = " + doubleMatrix.toString());
matlabEngine.close();
```

Prints the following to standard output:

`x =
0 1.0000 0.0000 -1.0000 -0.0000
doubleMatrix = [[0.0, 1.0, 1.2246467991473532E-16, -1.0, -2.4492935982947064E-16]]
`

Please have a look at the unit tests in the src package for more examples.

#### Test Console

`mat4j.sh`

/ `mat4j.bat`

is a Java console application for evaluating Matlab commands.

Predefined Java commands:

`exit`

/ `quit`

- Quits this application

`get varname`

- Converts Matlab variables to Java objects and calls toString()

`getImage hFigureVarName`

- Grabs a Matlab figure to a Java AWT Image

Example:

`>> x = [1:5];
>> get x
[[1.0, 2.0, 3.0, 4.0, 5.0]]
>> x
x =
1 2 3 4 5
`

#### Disclaimer

MATLAB is a registered trademark of The MathWorks, Inc.

Java and all of Oracle, Inc.'s Java-based trademarks and logos are trademarks

or registered trademarks of Oracle, Inc., in the US and/or other countries.