MATLAB Answers


How do I leverage the MATLAB Engine to deploy my MATLAB code over the web for an ASP.NET application using MATLAB 7.3 (R2006b)?

I would like to deploy my MATLAB code over the web using an ASP.NET application, and would like to use the MATLAB Engine API. I would prefer to use an existing example as a template.


1 Answer

Answer by MathWorks Support Team on 1 Jul 2015
 Accepted answer

This bug has been fixed in Release 2007b (R2007b). For previous product releases, read below for any possible workarounds:

This example demonstrates how to deploy a MATLAB Engine application on the Web using ASP.NET.

The attached example is an ASP.NET adaptation of MATLAB Web Server's webpeaks demo that calls the MATLAB Engine. This example was created with MATLAB 7.3 (R2006b) and Microsoft Visual Studio 2005; the exact steps may differ for other versions.

To build and execute this example,

1. Open Microsoft Visual Studio 2005 and select File->New->Website from the menu bar.

2. Select ASP.NET Web Site and then enter the location for the web site.

3. Download and extract the attached ZIP file to the directory created in step 2.

4. Start MATLAB and register it as a COM Automation Server as shown here:

This registration is done when installing MATLAB, but may need to be done again if you have several versions of MATLAB installed.

5. In MATLAB, set your current working directory to the directory created in step 2. Modify line 49 in ASPwebpeaks.m to point to the directory created in step 2. For example, if you created the project in C:\mydirectory, the line should read

print('-djpeg',['C:\mydirectory\' filename]);

6. In Microsoft Visual Studio, select Website->Add Existing Item and add the files peaksplot.aspx and peaksplot.aspx.vb to your web application project.

7. Select the file peaksplot.aspx in the Solution Explorer then select Website->Set As Start Page.

8. Modify line 37 of peaksplot.aspx.vb to read:

         myMATLAB.Execute("addpath C:\mydirectory\")

where mydirectory is the project directory in step 5.

9. Modify line 44 of peaksplot.aspx.vb to read:

 Image1.ImageUrl = "http://localhost/mydirectory/" & imagepath

where mydirectory is the project directory in step 5.

10. Configure MATLAB for DCOM access using the following instructions:

Make sure you use the ProgID Matlab.Application.Single (version 7.0) for user ASPNET, with full launch and access permissions.

11. Test the application by selecting Debug->Start Without Debugging

To test the application outside Microsoft Visual Studio you need to configure IIS so that the project folder is accessible and has the proper permissions for clients to run scripts and have write access. Additionally, you may need to configure IIS to use the proper version of ASP.NET.

For more information on MATLAB web deployment, see Tech Note 1608:

Note: MathWorks does not provide technical support for Microsoft Visual Studio, Microsoft Internet Information Services (IIS) and can only provide assistance on how to use our products' API and the API for components created with our products.


Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!