Simple Plot Example

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

Purpose

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

Procedure

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

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

      matlabroot\toolbox\dotnetbuilder\Examples\VS8\NET\PlotExample
    2. At the MATLAB command prompt, cd to the new PlotExample\PlotComp subdirectory in your work directory.

  2. Write the drawgraph function as you would any MATLAB function.

    This code is already in your work directory in PlotExample\PlotComp\drawgraph.m.

  3. While in MATLAB, issue the following command to open the Deployment Tool window:

    deploytool

  4. In MATLAB, Select File > New Deployment Project.

  5. In the New Deployment Project dialog box, select MATLAB Builder NE and .NET Component.

  6. Select PlotComp as the name of the project and click OK.

  7. In the Deployment Tool, select PlotComp.class and right-click. Select Rename and type Plotter.

  8. Select Generate Verbose Output.

  9. Add the drawplot.m file to the project.

  10. Save the project.

  11. Build the component by clicking the button in the Deployment Tool toolbar.

    The build process begins, and a log of the build appears in the Output pane of the Deployment Tool. The files that are needed for the component are copied to two newly created subdirectories, src and distrib, under the PlotComp directory. A copy of the build log is placed in the src directory.

    See What Happens in the Build Process? for more information.

  12. Write source code for a C# application that accesses the component.

    The sample application for this example is in matlabroot\toolbox\dotnetbuilder\Examples\VS8\PlotExample
    \PlotCSApp\PlotApp.cs
    .

    The program listing is shown here.

     PlotApp.cs

    The program does the following:

    The statement

     Plotter plotter= new Plotter(); 

    creates an instance of the Plotter class, and the statement

    plotter.drawgraph((MWNumericArray)plotValues);
    

    explicitly casts the native plotValues to MWNumericArray and then calls the method drawgraph.

  13. Build the PlotCSApp application using Visual Studio .NET.

    1. The PlotCSApp directory contains a Visual Studio .NET project file for this example. Open the project in Visual Studio .NET by double-clicking PlotCSApp.csproj in Windows® Explorer. You can also open it from the MATLAB desktop by right-clicking PlotCSApp.csproj > Open Outside MATLAB.

    2. If necessary, add a reference to the MWArray component, which is matlabroot\dotnetbuilder\bin\architecture\framework_version
      \mwarray.dll.

    3. If necessary, add (or fix the location of) a reference to the PlotComp component which you built in a previous step. (The component, PlotComp.dll, is in the \PlotExample\PlotComp\x86\V2.0\Debug\distrib subdirectory of your work area.)

  14. Build and run the application in Visual Studio .NET.

  


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