How do I deploy a MATLAB figure in a web application using MATLAB Builder for COM and ASP.NET?

6 views (last 30 days)
I would like to deploy the following MATLAB code using a web application:
load plotdata;
plot(plotdata);
where plotdata is a MAT-file created using the following MATLAB code:
plotdata = [1:10];
save plotdata;
I would like to see an example of how this can be done using ASP.NET.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 18 Apr 2023
Edited: MathWorks Support Team on 19 Apr 2023
The attached example is an ASP.NET application that uses a MATLAB Builder for COM component to deploy a simple MATLAB figure. In order to test this example, use the following steps:
1. Download example.zip into your Default Web Site Home Directory. In order to verify the identity of this directory:
a. Select Start->Run, then issue
inetmgr
at the Open field prompt.
b. Expand the local computer listing in the Internet Information Services (IIS) window, then expand the Web Sites folder.
c. Right-Click on Default Web Site, and select Properties.
d. Click on the Home Directory tab and verify the Local Path directory setting. This directory will be referred to as the <wwwroot> directory in the next steps. Note that if <wwwroot> matches C:\Inetpub\wwwroot and you have MATLAB Builder for COM 1.1.5 (R14SP3) or MATLAB Component Runtime 7.3 installed, you can skip steps 3-13.
e. Set the security settings for your <wwwroot> such that write permission is granted to all users. For more information regarding such settings, consult with your IIS documentation.
2. Extract the contents of the attached ZIP-file into <wwwroot>.
3. Start MATLAB and issue
edit <wwwroot>\WebApplication1\Simpleplot\myplot.m
at the MATLAB Command Prompt. Modify line 6 so that it reads:
print -djpeg <wwwroot>\WebApplication1\Simpleplot\matlabplot.jpg
Once this modification has been made, save and close this MATLAB file.
4. Issue
cd <wwwroot>\WebApplication
comtool
at the MATLAB Command Prompt.
5. Click on File->New Project and type
Simpleplot
at the Component name field, then click the Add button and click OK.
6. Expand the Simpleplotclass folder, and click on MATLAB files.
7. Click on the Add File button, and add <wwwroot>\WebApplication1\Simpleplot\myplot.m.
8. Repeat step 7 and add <wwwroot>\WebApplication1\Simpleplot\plotdata.mat (you will need to change the "Files of Type" field setting to "Other" in the "Add file to project" window in order to add a MAT-file).
9. Click on Build->COM Object.
10. Open
<wwwroot>\WebApplication1\WebApplication1.vbproj
11. Update the References listings in the Solution Explorer pane such that they include the Simpleplot COM object produced in step 9.
12. Right-click on WebForm1.aspx and set it to be the Start Page. Right-click on it once again and select View Code.
13. Modify line 35 of this code such that it reads:
fullSizeImg = System.Drawing.Image.FromFile("<wwwroot>\WebApplication1\matlabplot.jpg")
14. Hit Ctrl-F5, click on Save and select Yes.
Once step 14 is complete, you should be able to see a MATLAB plot embedded in a web browser.
For a more advanced example and further information regarding MATLAB's web application deployment using ASP.NET, please refer to the following webinar:
Note that the example mentioned in the webinar above requires that Optimization Toolbox be installed on your development machine. The files mentioned in this webinar can be downloaded from the following URL:
You can also find an additional information on web deployment at the following link: 

More Answers (0)

Categories

Find more on COM Component Integration in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!