Yesterday I completed some sample on Matlab Builder NE:
1. Magic Square Example – The Magic Square example shows you how to create a .NET component named MagicSquareComp, which contains the magic class and other files needed to deploy your application. (1m-file 1 class)
This example demonstrates how to use MATLAB Builder NE to build a simple ‘ component returning a magic square and how to convert MWNumericArray types’ to native .NET types.
2. Create Plot Example – 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). (1m-file 1 class)
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 handle the data needed by the drawgraph method to plot the equation.
- Uses a try-catch block to catch and handle any exceptions
This example demonstrates how to use MATLAB Builder NE to build a component that displays a MATLAB figure window.
This application demonstrates plotting x-y data by graphing a simple parabola into a MATLAB figure window.
3. Variable Arguments Example – (2 m-files 1 class)
Project Name: VarArgComp
Class Name: Plotter
M-Files: drawgraph.m, extractcoords.m
function [xyCoords] = DrawGraph(colorSpec, varargin),
function [varargout] = ExtractCoords(coords)
coords = plotter.extractcoords(5, data),
data = CType(plotter.drawgraph(colorSpec, coords), MWNumericArray)
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.
- How to build and run the VarArgDemoApp application, using the Visual Studio .NET development environment.
DRAWGRAPH Draws a graph using the specified color and connecting a variable number of input coordinates. Returns a single two column data array containing the input coordinates.XYCOORDS= DRAWGRAPH(COLORSPEC, VARARGIN) Connect coordinates using a line of the specified color.
EXTRACTCOORDS Extracts a variable number of two element x and y coordinate vectors from a two column array [VARARGOUT] = EXTRACTCOORDS(COORDS) Extracts x,y coordinates from a two column array
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
This example demonstrates how to use MATLAB Builder NE to build a component with a variable number of input and output arguments.
This application demonstrates how to call components having methods with varargin/vargout arguments.
4. Spectral Analysis Example – (2 class, 1m-file each)
Project Name: SpectraComp
Class Name: 1.Plotter > plotftt.m & 2.SignalAnalyzer>computeftt.m
How to use the MATLAB Builder NE product to create a component (SpectraComp) containing more than one class
- How to access the component in a C# application (SpectraApp.cs), including use of the MWArray class hierarchy to represent data
- How to build and run the application, using the Visual Studio .NET development environment
The program does the following:
- Constructs an input array with values representing a random signal with two sinusoids at 15 and 40 Hz embedded inside of it
- Creates an MWNumericArray array that contains the data
- Instantiates a SignalAnalyzer object
- Calls the computefft method, which computes the FFT, frequency, and the spectral density
- Instantiates a Plotter object
- Calls the plotfft method, which plots the data
- Uses a try/catch block to handle exceptions
This application computes and plots the power spectral density of an input signal.
5. Matrix Math Example – How to assign more than one MATLAB function to a component class (3 m-file 1 class)
How to assign more than one MATLAB function to a component class
How to manually handle native memory management by disabling the default memory manager for MWArray
- How to access the component in a C# application (MatrixMathApp.cs) by instantiating Factor and using the MWArray class library to handle data conversion
- How to build and run the MatrixMathApp application, using the Visual Studio .NET development environment
Project Name: MatrixMathComp
Class Name: factor M-Files: cholesky.m, ludecomp.m, and qrdecomp.m
function [L] = Cholesky(A)
function [L,U] = LUDecomp(A)
function [Q,R] = QRDecomp(A)
This application computes cholesky, LU, and QR factorizations of a finite difference matrix of order N. The order is passed into the application on the command line.
6. Phonebook Example – (1class, 1mfile) The makephone function takes a structure array as an input, modifies it, and supplies the modified array as an output.
Project Name:PhoneBookComp
Class Name: phonebook>makephone.m
getphone class demonstrates the use of the MWStructArray class
The program does the following:
- Creates a structure array, using MWStructArray to represent the example phonebook data.
- Instantiates the plotter class as thePhonebook object, as shown:
thePhonebook = new phonebook();
- Calls the makephone method to create a modified copy of the structure by adding an additional field, as shown:
result = thePhonebook.makephone(1, friends);