Example: The Magic Square Calculator On the Web

Category : Matlab Builder NE

To create the Magic Square Calculator using .NET, you must create:

  1. The MATLAB Builder NE DLL file that is generated by compiling M-code using MATLAB, MATLAB Compiler, and MATLAB Builder NE.
  2. The DataTable implementation that converts the magic square output into something that an ObjectDataSource can use in a GridView Control.
  3. The ASPX page and the code behind it. This page is responsible for taking in user input, displaying the controls, and handling page events.

1. create .net package

project name: Examples.prj

class name: MagicCalc

m files included: getMagic.m and get MagicWebFigure.m

2. create a c# project

3.create DataTable implementation. to do this create a .cs file and save it under /App_Code as MagicSquare.cs

save the source code and place it on the cs file

4.Create the code for the ASPX page – copy the source code

on this page I removed some of the codes..3 lines, some weird codes that give errors

5. Create the code behind the ASPX page – copy the source code

6. don’t forget to add references:  examples.dll, mwarray.dll

here’s a successful one:

Links on MATLAB Builder NE

Category : Matlab Builder NE


Deploying Applications with MATLAB

Using MATLAB Builder NE

Deployment of a Soundcard Audio Analysis Application


Deploying MATLAB Applications to the Web – Calculation Services .Net

Deploying MATLAB Components to C/C++, Java, .NET, and Excel

Documentation – Matlab Compiler


- Calculation Services .Net

Working on getMagicWebFigure example

Category : Matlab Builder NE

The examples doesn’t really show exactly how to do it. There’s some missing files. Isuppose they want us to figure out ourselves. Anyway as usual, lots of errors and warning as I trying to figure out the whole thing

Here’s one of them:

Validation (XHTML 1.0 Transitional): Attribute values must be enclosed in quotation marks.


solution-add “” ->media=”all”


Sharing Components Across Distributed Applications Using .NET Remoting

Category : Matlab Builder NE

Now I’m trying to figure out the example in this section. As always, there’s always obstacle. I wonder why does the examples doesn’t work. You always need to to adjust something.

Here’s an error

Warning 1 ‘System.Runtime.Remoting.RemotingConfiguration.Configure(string)’ is obsolete: ‘Use System.Runtime.Remoting.RemotingConfiguration.Configure(string fileName, bool ensureSecurity) instead.’ D:\MagicRemoteExample\MWArrayAPI\MagicSquareServer\MagicSquareServer.cs 10 11 MagicSquareMWServer

So I did some Googling..but heck couldn’t understand



After looking at the explanation i’ve changed

static void Main(string[] args)
Console.WriteLine(“Magic Square Server started…”);

static void Main(string[] args)        {          RemotingConfiguration.Configure(@”..\..\..\..\MagicSquareServer.exe.config”);
Console.WriteLine(“Magic Square Server started…”);
Console.ReadLine();        }


public static void Configure(string MagicSquareServer,bool ensureSecurity)


Console.WriteLine(“Magic Square Server started…”);



Now the error that comes out

Error 1 Program ‘D:\MagicRemoteExample\MWArrayAPI\MagicSquareServer\obj\Debug\MagicSquareServer.exe’ does not contain a static ‘Main’ method suitable for an entry point MagicSquareMWServer

Webfigures works!!!

Category : Matlab Builder NE

Alhamdulillah..I managed to figure out the whole thing..

Patient is a virtue

Matlab Builder NE -Sample Applications

Category : Matlab Builder NE

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);

    Referenced assembly ‘MWArray.dll’ targets a different processor

    Category : Matlab Builder NE

    Stumble with theis problem:

    Possible problem detected while building assembly
    ‘MagicSquareVBApp’: Referenced assembly ‘MWArray.dll’
    targets a different processor

    Did a google search on “Referenced assembly ‘MWArray.dll’ targets a different processor”

    Here’s some of the results



    I did some trial and error, and here’s the solution that I got. The problem rise because of the platform setting between your local machine i.e. cpu and visual studio conflict with each other. My local machine is x86 while VS is x64 by default.

    So you need to change it at Build>Configuration Manager and at your project file, go to property and change it to the type your local machine is.

    Matlab Builder NE Resources

    Category : Matlab Builder NE

    Matlab Builder NE

    http://www.mathworks.com/access/helpdesk/help/toolbox/dotnetbuilder/ – Help Online


    http://www.mathworks.com/products/netbuilder/demos.html – videos

    http://www.mathworks.com/access/helpdesk/help/toolbox/dotnetbuilder/ – documentation

    http://www.mathworks.com/matlabcentral/fileexchange/?term=productid:46 – File Exchange

    http://www.codeproject.com/KB/dotnet/matlabeng.aspx?msg=3114587 – 1..2..3 ways of integrating MATLAB with the .NET


    http://www.mathworks.com/matlabcentral/fileexchange/?term=productid:46 – Builder NE

    http://www.mathworks.com/matlabcentral/fileexchange/22477-dotnet-web-example-guide-end-to-end-chapter – Builder NE/magic calculator








    http://groups.google.com/group/comp.soft-sys.matlab/browse_thread/thread/a97b6aecc5087a1a?pli=1 – stops me building the Visual Studio Project.

    http://stackoverflow.com/questions/2542049/matlab-builder-ne-net-assembly-data-type-question – data types

    http://www.mathworks.com/matlabcentral/newsreader/view_thread/247954 – reinstalling builder NE

    Matlab in General

    http://www.mathworks.com/support/ – find all documentations here

    http://www.mathworks.com/matlabcentral/ – file exchange, newsgroup, blogs…