Control MATLAB from Java, forked from matlabcontrol
Clone or download
Permalink
Failed to load latest commit information.
.ci Fixed CI scripts. Oct 15, 2015
META-INF Publish 4.5.0. Jul 18, 2017
gradle/wrapper Gradle 2.13 -> 3.4.1 Mar 15, 2017
src code review fixes Jul 18, 2017
test/matlabcontrol Bump spotless to 1.3.3 and license to 2016. Apr 28, 2016
.gitignore Added gradlew to the root directory. Oct 6, 2015
.travis.yml Getting rid of client-side secrets, adding caching. Oct 8, 2015
CHANGES.md Publish 4.5.0. Jul 18, 2017
CODE_OF_CONDUCT.md Create CODE_OF_CONDUCT.md Feb 2, 2018
CONTRIBUTING.md Improved the README's links to the demo and instructions for running … Oct 16, 2015
LICENSE Bump spotless to 1.3.3 and license to 2016. Apr 28, 2016
PULL_REQUEST_TEMPLATE.md Create PULL_REQUEST_TEMPLATE.md Feb 2, 2018
README.md Bump to 4.6.0-SNAPSHOT. Jul 18, 2017
build.gradle Removed deprecated left-shift operator. Mar 15, 2017
gradle.properties Bump to 4.6.0-SNAPSHOT. Jul 18, 2017
gradlew Gradle 2.13 -> 3.4.1 Mar 15, 2017
gradlew.bat Gradle 2.13 -> 3.4.1 Mar 15, 2017
matconsolectl.png Unable to contact original author, and just the fact that the maven g… Oct 15, 2015
matconsolectl.svg Unable to contact original author, and just the fact that the maven g… Oct 15, 2015
settings.gradle The demo is so small, it's fine to package it with the actual code, a… Oct 15, 2015
spotless.eclipseformat.xml Bump spotless to 3.0.0. Jan 10, 2017
spotless.importorder Added formatting enforcement for everything besides java code. Oct 6, 2015
spotless.license.java Bump spotless to 1.3.3 and license to 2016. Apr 28, 2016

README.md

MatConsoleCtl: Control MATLAB from Java

Maven artifact Latest version Javadoc License Apache

Changelog Travis CI

MatConsoleCtl is a Java API that allows calling MATLAB from Java. You can eval, feval, as well as get and set variables. Interaction can be performed from either inside MATLAB or outside MATLAB (both by starting a new MATLAB or by connecting to an existing MATLAB).

MatlabProxyFactoryOptions.Builder builder = new MatlabProxyFactoryOptions.Builder();
// setup the factory
//    setCopyPasteCallback() connects to an existing MATLAB by copy-pasting a few lines into the command window
//    setUsePreviouslyControlledSession() starts a new MATLAB or connects to a previously started MATLAB without any user intervention

MatlabProxyFactory factory = new MatlabProxyFactory(builder.build());
// get the proxy
MatlabProxy proxy = factory.getProxy();
// do stuff over the proxy
proxy.eval("disp('hello world!)")
proxy.setVariable("a", 5.0);
Object a = proxy.getVariable("a");
double actual = ((double[]) result)[0];
assert(actual == 5.0)
// disconnect the proxy
proxy.disconnect();

Javadoc links for MatlabProxyFactoryOptions.Builder and MatlabProxy.

Contributions are welcome, see the contributing guide for development info.

Demo

MatConsoleCtl includes a demo GUI. Below is a script you can use to run the demo inside of MATLAB:

version = '4.5.0';
tempdir = 'matconsolectl_demo';

% make a directory to copy the jar into
mkdir(tempdir);
% download the jar
URL = ['https://repo1.maven.org/maven2/com/diffplug/matsim/matconsolectl/' version '/matconsolectl-' version '.jar'];
filename = [tempdir '/matconsolectl-' version '.jar'];
websave(filename,URL);
% add it to the path
javaaddpath([pwd '\' filename]);

% run it
matlabcontrol.demo.DemoMain

You can also run the demo outside of MATLAB by downloading the jar, then running java -jar matconsolectl-4.5.0.jar at a console.

Compatibility

MatConsoleCtl works on Win/Mac/Linux, MATLAB R2007b through R2016b, and it will continue to work so long as MATLAB maintains the Java MATLAB Interface.*

* On OS X 10.5, R2009a and earlier, you will need to do some hacking. matlabcontrol requires Java 6, and Apple only released 64-bit Java 6 for OS X 10.5, while MATLAB only released 32-bit MATLAB for R2009a and earlier. There are unofficial ways to run 32-bit Java 6 on OS X 10.5.

Acknowledgements

This is forked from the matlabcontrol project originally maintained on the now-defunct Google Code. The name was changed to ensure that we don't infringe the original project's license, but we did not change the package names, so this project is binary compatible with the original matlabcontrol. We are very thankful to Joshua Kaplan for creating matlabcontrol, but this fork is in no way associated with or endorsed by any authors of the original project.

We have fixed some bugs and added some features (see the changelog), and we will maintain this library into the future. We're happy to accept pull requests too!