tags:

views:

333

answers:

3

I need to import a plot graph from matlab into java swing GUI? Is there any way to do it?

A: 

This probably isn't the best way to do it... but you could save your data from MATLAB in a convenient format, and then load it in Swing using JFreeChart.

colinjameswebb
+2  A: 

If matlab saves the plot as an image file (say, GIF or PNG or something) then you can use Toolkit.getImage() or createImage() to read it in and then

  • display it on a Swing component either as an IconImage (for those components that have icons, such as JLabel) or

  • draw it in a component's paintComponent() method using drawImage() .

Carl Smotricz
+1 for non-interactive plots this is definitively the easiest way.
Mikhail
The Matlab print() function, using the -d option, can export a figure to image files or the system clipboard in various formats. See "doc print".
Andrew Janke
Sure beats doing graphs with a ruler and pencil!!
Carl Smotricz
A: 

You could also use something like this to evaluate your Matlab script directly in Java and then use the results to create your plot with swing.

Edit:

As Jeff Storey mentioned in his comment, the suggested method is of course used for online evaluation in the Java environment.

If you want to do the computations in Matlab and just display the chart in Java, then I would suggest storing the chart values in a file (e.g. .mat file or just a binary file) and then using a Java chart library (like JFreeChart) to draw the chart.

I wouldn't recommend storing the chart as an image file using Matlab and then loading it from Java to display it. The file will probably be larger and the quality will be much degraded compared to the above mentioned methods.

3lectrologos
This should work, but it really depends if the Matlab graph was created offline or needs to be created at runtime during the java application.
Jeff Storey