| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB Builder NE |
| Contents | Index |
| Learn more about MATLAB Builder NE |
| On this page… |
|---|
The drawgraph function displays a plot of input parameters x and y. The purpose of the example is to show you how to:
Use the MATLAB Builder NE product to convert a MATLAB function (drawgraph) to a method of a .NET class (Plotter) and wrap the class in a .NET component (PlotComp).
Access the component in a C# application (PlotApp.cs) by instantiating the Plotter class and using the MWArray class library to handle data conversion.
Note For complete reference information about the MWArray class hierarchy, see the MWArray Class Library Reference (available online only). |
Build and run the PlotCSApp application, using the Visual Studio .NET development environment.
If you have not already done so, copy the files for this example as follows:
Copy the following folder that ships with the MATLAB product to your work folder:
matlabroot\toolbox\dotnetbuilder\Examples\VS8\NET\PlotExample
At the MATLAB command prompt, change folder to the new PlotExample\PlotComp subfolder in your work folder.
Write the drawgraph function as you would any MATLAB function.
This code is already in your work folder in PlotExample\PlotComp\drawgraph.m.
While in MATLAB, issue the following command to open the Deployment Tool window:
deploytool
Build the .NET component. See the instructions in Building Your Component for more details. Use the following information:
| Project Name | PlotComp |
| Class Name | Plotter |
| File to compile | drawplot.m |
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.
The program does the following:
Creates two arrays of double values
Creates a Plotter object.
Calls the drawgraph method to plot the equation using the MATLAB plot function.
Uses MWNumericArray to represent the data needed by the drawgraph method to plot the equation.
Uses a try-catch block to catch and handle any exceptions.
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.
Build the PlotCSApp application using Visual Studio .NET.
The PlotCSApp folder 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.
Add a reference to the MWArray component,
which is matlabroot\toolbox\dotnetbuilder\bin\architecture\framework_version
\mwarray.dll.
Add or, if necessary, 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 subfolder of your work area.)
Build and run the application in Visual Studio .NET.
![]() | Sample Applications (C#) | Passing Variable Arguments | ![]() |

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 |