| 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 |
Note This example is similar to Simple Plot Example, except that the MATLAB function to be encapsulated takes a variable number of arguments instead of just one. |
The purpose of the example is to show you the following:
How to use the builder to convert a MATLAB function, drawgraph, which takes a variable number of arguments, to a method of a .NET class (Plotter) and wrap the class in a .NET component (VarArgComp). The drawgraph function (which can be called as a method of the Plotter class) displays a plot of the input parameters.
How to access the component in a C# application (VarArgApp.cs) by instantiating the Plotter class and using MWArray to represent data.
Note For complete reference information about the MWArray class hierarchy, see the MWArray Class Library Reference (available online only). |
How to build and run the VarArgDemoApp application, using the Visual Studio .NET development environment.
Step-by-Step Procedure
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\VarArgExample
At the MATLAB command prompt, cd to the new VarArgExample subfolder in your work folder.
Write the MATLAB functions as you would any MATLAB function.
The code for the functions in this example is as follows:
This code is already in your work folder in /VarArgExample/VarArgComp/.
While in MATLAB, issue the following command to open the Deployment Tool dialog box:
deploytool
Build the .NET component. See the instructions in Building Your Component for more details. Use the following information:
| Project Name | VarArgComp |
| Class Name | Plotter |
| File to compile | extractcoords.m |
Write source code for an application that accesses the component.
The sample application for this example is in VarArgExample\VarArgCSApp\VarArgApp.cs.
The program listing is shown here.
The program does the following:
Initializes three arrays (colorSpec, data, and coords) using the MWArray class library
Creates a Plotter object
Calls the extracoords and drawgraph methods
Uses MWNumericArray to represent the data needed by the methods
Uses a try-catch block to catch and handle any exceptions
The following statements are alternative ways to call the drawgraph method:
data= (MWNumericArray)plotter.drawgraph(colorSpec,
coords[0], coords[1], coords[2],coords[3], coords[4]);
...
data= (MWNumericArray)plotter.drawgraph((MWArray)colorSpec, coords);
Build the VarArgApp application using Visual Studio .NET.
The VarArgCSApp folder contains a Visual Studio .NET project file for this example. Open the project in Visual Studio .NET by double-clicking VarArgCSApp.csproj in Windows Explorer. You can also open it from the MATLAB desktop by right-clicking VarArgCSApp.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 VarArgComp component which you built in a previous step. (The component, VarArgComp.dll, is in the \VarArgExample\VarArgComp\x86\v2.0\debug\distrib subfolder of your work area.)
Build and run the application in Visual Studio .NET.
![]() | Simple Plot Example | Spectral Analysis Example | ![]() |

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 |