The following example illustrates using waitForFigures from
a Java® application. The example uses a Java class created
by the MATLAB® Compiler SDK™ product; the object encapsulates MATLAB code
that draws a simple plot.
Create a work folder for your source code. In this example,
the folder is D:\work\plotdemo.
In this folder, create the following MATLAB file:
drawplot.m
function drawplot()
plot(1:10);
Use the compiler to create a Java package with the following properties:
| Package name | examples |
| Class name | Plotter |
Create a Java program in a file named runplot.java with
the following code:
import com.mathworks.toolbox.javabuilder.*;
import examples.Plotter;
public class runplot
{
public static void main(String[] args)
{
try
{
plotter p = new Plotter();
try
{
p.showPlot();
p.waitForFigures();
}
finally
{
p.dispose();
}
}
catch (MWException e)
{
e.printStackTrace();
}
}
} Compile the application with the javac command.
When you run the application, the program displays a plot from 1 to 10 in a MATLAB figure window. The application ends when you dismiss the figure.
Note:
To see what happens without the call to |