Products & Services Solutions Academia Support User Community Company

Learn more about MATLAB Builder JA   

Plot Example

Purpose

The purpose of the example is to show you how to do the following:

The drawplot function displays a plot of input parameters x and y.

Procedure

  1. If you have not already done so, copy the files for this example as follows:

    1. Copy the following folder that ships with MATLAB to your work folder:

      matlabroot\toolbox\javabuilder\Examples\PlotExample
      
    2. At the MATLAB command prompt, cd to the new PlotExample subfolder in your work folder.

  2. If you have not already done so, set the environment variables that are required on a development machine. See Settings for Environment Variables (Development Machine).

  3. Write the drawplot function as you would any MATLAB function.

    The following code defines the drawplot function:

    function drawplot(x,y)
    plot(x,y);
    

    This code is already in your work folder in PlotExample\PlotDemoComp\drawplot.m.

  4. While in MATLAB, issue the following command to open the Deployment Tool Window:

    deploytool

  5. You create a Java application by using the Deployment Tool GUI to build a Java class that wraps around your M-code.

    To compile or build the Java application using the Deployment Tool, use the following information as you work through this example in Building the Java Component:

    Project Nameplotdemo
    Class Nameplotter
    File to compiledrawplot.m

  6. Write source code for an application that accesses the component.

    The sample application for this example is in matlabroot\toolbox\javabuilder\Examples\PlotExample
    \PlotDemoJavaApp\createplot.java
    .

    The program graphs a simple parabola from the equation .

    The program listing is shown here.

     createplot.java

    The program does the following:

    • Creates two arrays of double values, using MWNumericArray to represent the data needed to plot the equation.

    • Instantiates the plotter class as thePlot object, as shown:

      thePlot = new plotter();
    • Calls the drawplot method to plot the equation using the MATLAB plot function, as shown:

      thePlot.drawplot(x,y);
      
    • Uses a try-catch block to catch and handle any exceptions.

  7. Compile the createplot application using javac. When entering this command, ensure there are no spaces between path names in the matlabroot argument. For example, there should be no space between javabuilder.jar; and .\distrib\plotdemo.jar in the following example. cd to your work folder. Ensure createplot.java is in your work folder

    • On Windows, execute this command:

      javac -classpath
        .;matlabroot\toolbox\javabuilder\jar\javabuilder.jar;
        .\distrib\plotdemo.jar createplot.java
      
    • On UNIX, execute this command:

      javac -classpath
        .:matlabroot/toolbox/javabuilder/jar/javabuilder.jar:
        ./distrib/plotdemo.jar createplot.java
      

  8. Run the application.

    To run the createplot.class file, do one of the following:

    • On Windows, type:

      java -classpath
        .;matlabroot\toolbox\javabuilder\jar\javabuilder.jar;
        .\distrib\plotdemo.jar 
        createplot
      
    • On UNIX, type:

      java -classpath
        .:matlabroot/toolbox/javabuilder/jar/javabuilder.jar:
        ./distrib/plotdemo.jar 
         createplot
      

      Note   The supported JRE version is 1.6.0. To find out what JRE you are using, refer to the output of 'version -java' in MATLAB or refer to the jre.cfg file in matlabroot/sys/java/jre/arch or mcrroot/sys/java/jre/arch.

      Note   If you are running on Mac or Solaris 64-bit platforms, you must add the -d64 flag in the Java command. See Limitations and Restrictions for more specific information.

    The createplot program should display the output.

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS