Connecting Mat lab from Netbeans

4 views (last 30 days)
Malithi
Malithi on 28 Jan 2014
Commented: Ned Twigg on 20 Oct 2015
Hi, I want to connect to Matlab from netbeans and read some image files and do image processing. It works fine in last month,i did all the testing for my final reaserch and it worked fine. This is my cording to connect with Matlab,
MatlabProxyFactoryOptions options = new MatlabProxyFactoryOptions.Builder().setUsePreviouslyControlledSession(true).build();
MatlabProxyFactory factory = new MatlabProxyFactory(options);
MatlabProxy proxy=factory.getProxy();
// call builtin function
String curr="";
for (int i = 0; i < r.fileread(path).length; i++) {
curr=r.fileread(path)[i]+"\\*.bmp";
String out=r.fileread(path)[i]+".txt";
String newfile=r.fileread(path)[i]+"_new.txt";
//execute the addapth path command in matlab
proxy.eval("addpath('D:\\finalwk')");
//execute user defined functions
proxy.feval("Untitled",r.fileread(path)[i],curr,out);
proxy.feval("uni",out,newfile);
}
Now it dose not run from MatlabProxy proxy=factory.getProxy(); statement it opens Matlab and and gives a huge error,
Reconnecting to this session of MATLAB will not be possible matlabcontrol.MatlabConnectionException: Could not register this session of MATLAB at matlabcontrol.MatlabBroadcaster.bindSession(MatlabBroadcaster.java:144) at matlabcontrol.MatlabBroadcaster.broadcast(MatlabBroadcaster.java:92) at matlabcontrol.MatlabConnector$EstablishConnectionRunnable.run(MatlabConnector.java:209) at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source) at java.util.concurrent.FutureTask.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: java.rmi.ConnectException: Connection refused to host: localhost; nested exception is: java.net.ConnectException: Connection timed out: connect at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)...
Can Some one give an idea as soon as possible. Thanks
  1 Comment
Ned Twigg
Ned Twigg on 20 Oct 2015
Hi there! It's probably too late to help you with this particular project, but you might like to know about MatConsoleCtl.
matlabcontrol is fantastic, but it hasn't been updated in a couple years.
I've created a binary-compatible fork on GitHub which is actively maintained called MatConsoleCtl.
Relative to matlabcontrol, it contains these changes
  • available on Maven Central as com.diffplug.matsim:matconsolectl
  • a way to connect to an existing MATLAB session by copy-pasting a string of text to the MATLAB console
  • more descriptive error messages in exceptions
  • compatibility with OSGi classloaders
  • fixed all compiler warnings
  • fixed several tricky bugs which were found by FindBugs
I'm happy to accept any GitHub Issues or Pull-Requests, and I'll be keeping it up-to-date and tested.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!