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.
In addition to this tech note, there is also an example guide that provides additional information on deploying MATLAB applications to the web using MATLAB Builder JA and MATLAB Builder NE.
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 JA and MATLAB Builder NE). 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.
| Platform | Application Server Does Not have MATLAB | Application Server Does have MATLAB |
|---|---|---|
| Windows | MATLAB Builder NE MATLAB Builder JA |
MATLAB COM Automation |
| Linux/Unix | MATLAB Builder JA | CGI with MATLAB as an Executable |
| MAC | CGI with an Executable Built by MATLAB Compiler | CGI with MATLAB as an Executable |
Builder NE requires MATLAB and the MATLAB Compiler. The examples below use .NET or COM components from Builder NE with ASP.NET, which requires IIS.
Sudoku Web Application (ASP.NET)
For more information on solving Sudoku puzzles, check out the following reference:
Delahaye, Jean-Paul. "The Science Behind Sudoku."
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 NE Sudoku files from MATLAB Central:
The following sample applications require additional toolboxes:
Here are some pointers for ASP.NET deployment:
If this step is not performed, the application displays an error pointing to the web.config file (depends on your application).
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>
Our sample Builder JA applications use Java front ends with the Tomcat servlet container/Web server.
The following sample application requires additional toolboxes:
There is also a Web Services example using Builder JA, with no toolboxes from File Exchange on MATLAB Central:
http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=12689&objectType=FILE
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:
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 MATLAB 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.
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.