Create a GUI in Java and calling Matlab scripts from Java

15 views (last 30 days)
Hey all,
I currrently have a functioning Matlab script (and a few other scripts that help with it) that uses avifile, addframe and implay to create and then play back a movie of an animation I have made. The animation loops through .mat files that have
I currently have a 2D animation where I use the image function to create a 4x11 set of small boxes, each representing an individual sensor in a larger scheme of sensors implanted in the ground. In the animation, the color of each box corresponds to the scalar value of the acceleration reading for each sensor. I created the animation by using creating an aviobj using the avifile() function, then using a loop to update the color values and the object with a new figure representing the data using addframe(). I save the AVI file, then I play it back with implay() so I can have the play/pause features.
Now, I was thinking of writing some Java code and making a Java program with a GUI that in some user input for a filename/time period for the data to be used (or some user input like that) and then call the appropriate Matlab scripts from Java. How might I make this happen? I read about the matlabcontrol API and was considering that but am looking for other potential ways to handle this. A potential alternative would be to have the animation carried out from Java? Anything helps, thanks in advance
NathanF

Accepted Answer

Titus Edelhofer
Titus Edelhofer on 26 Jul 2011
Hi,
there are several points here to clarify: first of all, why not write the GUI in MATLAB? From your description it seems, that it will not be a hyper-fancy-crowded-with-lots-of-complicated-controls type of GUI, which will be easy to implement in MATLAB.
If it "must" be Java, then (from an implementation point of view) using MATLAB Builder JA would be the simplest approach. Other approaches would be to start MATLAB with the "-r" parameter as a batch processing. Deciding between these options depend on whether other people would like to use the GUI+Computation, and if they have MATLAB or not.
Titus

More Answers (1)

Yair Altman
Yair Altman on 7 Aug 2011
You can use the MatlabControl Java package to call Matlab directly from Java without needing the Matlab Builder JA toolbox: http://UndocumentedMatlab.com/blog/jmi-wrapper-remote-matlabcontrol/
  1 Comment
Ned Twigg
Ned Twigg on 20 Oct 2015
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.

Categories

Find more on Text Data Preparation in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!