Web Deployment of MATLAB Applications Guide

from:http://www.mathworks.cn

Web Deployment of MATLAB Applications Guide


As of R2006b, the MATLAB Web Server product has been discontinued. Going forward, there are several options for making your MATLAB applications available via the Web. Each of the examples below contains code that you may use as a template, along with a readme file describing the steps required to create the application. We will continue to add links to more examples over time.

The Software License Agreement has been modified to state MATLAB users on concurrent licenses or "designated computer" individual licenses (installed on a single computer) may access their MATLAB applications from web pages. At no time is it legal to access the MATLAB command prompt from a web page.

Contents

  1. Recommended Deployment Options
  2. Using MATLAB Builder for .NET to create a server-side COM or .NET component
  3. Using MATLAB Builder for Java to create a Java servlet or a Web Service
  4. Calling MATLAB functions via CGI
  5. Accessing MATLAB algorithms directly from the Web, using COM automation, or other technologies

Section 1: Recommended Deployment Options

You may choose to create Web applications that access MATLAB directly (hosting MATLAB on the application server), or by building executables or components using the MATLAB deployment products (MATLAB Compiler, MATLAB Builder for Java and MATLAB Builder for .NET). Deployed applications do not require MATLAB, and may be deployed royalty-free to as many servers as you wish.

The following table lists recommended deployment options for each platform, but other options are possible.

PlatformApplication Server Does Not have MATLABApplication Server Does have MATLAB
WindowsMATLAB Builder for .NET

MATLAB Builder for Java
MATLAB COM Automation
Linux/UnixMATLAB Builder for JavaCGI with MATLAB as an Executable
MACCGI with an Executable Built by MATLAB CompilerCGI with MATLAB as an Executable


Section 2: Using MATLAB Builder for .NET to create a server-side COM or .NET component

Builder for .NET requires MATLAB and the MATLAB Compiler. The examples below use .NET or COM components from Builder for .NET with ASP.NET, which requires IIS.

Sudoku Web Application (ASP.NET)

 

  • SOLVE_SUDOKU.M -- This file contains the code for solving the Sudoku board, and should be deployed as a .NET assembly. It accepts as input a 9-by-9 array, where 0 represents a blank square, and the digits 1-9 represent any initial values in the grid. The function returns the solved board, if a solution exists, and a flag indicating whether the code was successful at finding a solution. To solve the puzzle, the code uses an algorithm that makes recursive calls to the solver function after choosing one of the possible candidates for a square. If a square does not have any possible candidates, the algorithm backs up to a previous square, and tries another possible candidate there before proceeding.

     

  • SUDOKU.ASPX -- The front-end Web page is an ASP.NET file that creates a 9-by-9 grid of text boxes, allowing users to enter the values for a Sudoku puzzle. After a user clicks the Submit button, this code posts the data in the grid to solver.aspx.

     

  • SOLVER.ASPX -- This ASP.NET code accepts the input data from sudoku.aspx, packages it in a .NET array, and calls a method of the Sudoku object to solve the puzzle. After receiving the output in the form of a two-dimensional array, the ASP.NET code formats the array to display the solution on the screen.

     

For more information on solving Sudoku puzzles, check out the following reference:
Delahaye, Jean-Paul. "The Science Behind Sudoku." Scientific American, June 2006: 81-83.

Note: Certain boards take longer to solve than others. It may be helpful to set the timeout for the ASP.NET page appropriately for boards that take an excessive amount of time to complete.

You may download the MATLAB Builder for .NET Sudoku files from MATLAB Central:

Sudoku: ASP.NET/MATLAB

http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=12096&objectType=file

 

Surf Peaks Example Using .NET

http://www.mathworks.com/support/solutions/data/1-2EETRY.html

The following sample applications require additional toolboxes:

 

Black-Scholes Option Value application (either .NET or COM components):

http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=12098&objectType=file

 

Gene Expression Web application using .NET:

http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=10344&objectType=file

Gene Expression Web application using COM:

http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=9418&objectType=file

 

General pointers for using ASP.NET with MATLAB

Here are some pointers for ASP.NET deployment, particularly for customers transitioning from MATLAB Web Server:

 

  • In M-code, you need to use the print command to save the figure to a JPEG format as opposed to wsprintjpeg.
  • You must ensure that IIS points to the correct version of ASP.NET (as selected during compilation). After publishing the ASP.NET application to the web using the Publish to Web option in Visual Studio, setting the correct version is accomplished by:
    1. Select Start > Control Panel > Administrative Services > Internet Information Services.
    2. Drill down from Local Computer > Web Sites > WebApp, where WebApp corresponds to the virtual directory that points to the ASP.NET application's project folder.
    3. Right-click this directory and select the Properties option.
    4. Click the ASP.NET tab and specify the appropriate version using the dropdown menu.

    If this step is not performed, the application displays an error pointing to the web.config file (depends on your application).

  • MATLAB Web Server HTML tags needed modification for ASP.NET/design mode compatibility:

    tags caused errors for design mode, and the page would not display in this mode. Errors were very helpful in providing guidance on needed changes.

    You are required to convert HTML controls to ASP control format (drop-down menus, text fields, etc.). For example, an HTML text field is expressed as follows:

    <input type="text" size="5" name="AZ" maxlength="5" value="-37.5" ID="Text1">

    Its ASP control equivalent is expressed as:

    <asp:Textbox id="AZ" runat="server" Width="60px">-37.5"</asp:Textbox>

  • If prohibiting client write access for the virtual directory containing the ASP.NET web application, pre-extraction of the CTF-archive file is necessary.

 

Section 3: Using MATLAB Builder for Java to create a Java servlet or a Web Service

Our sample Builder for Java applications use Java front ends with the Tomcat servlet container/Web server.

 

MATLAB Builder for Java: Web Surface Peaks example using a JAVA Component

The following sample application requires additional toolboxes:

 

Web Black-Scholes Option Value (JAVA component)

 

There is also a Web Services example using Builder for Java, with no toolboxes from File Exchange on MATLAB Central.

 

 

Section 4: Calling MATLAB functions via CGI

MATLAB can be called directly as an executable via CGI, or executables created with the MATLAB Compiler can be created and deployed. We currently have Technical Support example solutions available on our website:

 

Can I create a CGI executable that calls a shared library using the MATLAB Compiler to deploy my application on the Web?

http://www.mathworks.com/support/solutions/data/1-2YVMOV.shtml

 

 

Can I create a standalone CGI executable to deploy my application on the Web using the MATLAB Compiler?

http://www.mathworks.com/support/solutions/data/1-30REEY.shtml

 

 

Section 5: Accessing MATLAB algorithms directly from the Web, using COM automation, or other technologies

 

  1. Call MATLAB through its COM automation interface, similarly to how you would call a COM object from MATLAB Builder for .NET.
  2. Wrap the MATLAB COM automation interface as a Web service:

 

Implementation of MATLAB Web Services Interface:

This thin wrapper uses the MATLAB functions PutWorkspaceData and GetWorkspaceData to pass data values, and then passes a string of XML to MATLAB to be processed, so the user can access MATLAB functions they have written.

Note that the MathWorks Software License Agreement specifically forbids exposing the MATLAB command line, i.e. allowing the end users of the Web site to define the XML string to execute. Instead, this approach must be used in the context of an application, executing specific user-created M-functions.

 

[WebService(Namespace = "http://www.mathworks.com/demo")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
    MLApp.MLAppClass myMATLAB;

    public Service () {
        // Start MATLAB
        myMATLAB = new MLApp.MLAppClass();
    }

    [WebMethod]
    public string ProcessXml(string aInputXml)
    {
        object outputXml;

        // Put data into MATLAB
        myMATLAB.PutWorkspaceData("transIn","base", , aInputXml);

        // Execute our UserDefined function
        myMATLAB.Execute("TxRequest");

        // Retrieve the result
        myMATLAB.GetWorkspaceData("transOut", "base", out outputXml);

        return outputXml.ToString();
    }
}

One key aspect in the design is the timing of when to start up MATLAB and when to call the commands to process the data. As shown above, we initialized our MATLAB application when the service was initiated. This causes MATLAB to start if a copy was not already running with the automation on. Then when the user calls ProcessXml only the data communication needs to occur.

If you plan to call the ProcessXml function often and expect accessing this function simultaneously from multiple threads, you need to take further action to handle the locking of access to MATLAB while in this method.

Calling Perl Programs from MATLAB

On Windows, it is also possible to call MATLAB from PHP or Perl, using COM automation. Perl supports using MATLAB arrays as detailed below. PHP can only accept scalar values from MATLAB due to the limitations of its COM array implementation. Details and example code are included in a biology demo on MATLAB Central.

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值