Adilya Taimussova
Adilya Taimussova

Reputation: 551

java and matlab Integration

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

Upvotes: 1

Views: 1761

Answers (3)

3lectrologos
3lectrologos

Reputation: 9662

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.

Upvotes: 0

Carl Smotricz
Carl Smotricz

Reputation: 67820

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() .

Upvotes: 2

colinjwebb
colinjwebb

Reputation: 4378

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.

Upvotes: 0

Related Questions