Can I run MATLAB code on a web site?

building a website with matlab
matlab online server
website matlab
matlab interact with website
embed matlab in website
run matlab code in html
matlab web app
convert matlab to javascript

I have a BE project whose code is in MATLAB but I need to present results on a web page. I want to know whether I can run my code directly on a web site? If not, could you tell me which language would be a better option? I'm thinking maybe ASP, HTML and PHP.

You can compile your MATLAB application into a stand-alone executable using MATLAB compiler.

Type "mcrversion" at the prompt to determine whether you have this package installed- It's likely that you don't if you haven't paid for it- As with most extensions that Mathworks provides, you need to pay for it.

If you don't need to compile your code, but simply run it, you may be able to invoke MATLAB through the command line to do what you need it to.

As Sinan mentioned, you would use a function like passthu in both of these cases.

Another alternative is to create an extension for PHP to utilize MATLAB in C. MATLAB provides a C API which allows you to call the engine using libraries that come with MATLAB (see your "extern" folder for examples).

See the following link on creating the extension (It is quite easy):

Search for "MATLAB C/ Fortran API" in MATLAB or google for the documentation on functions. Basically, you'll probably need to call EngOpen to call the engine and return a pointer.

Evaluate a string using engEvalString (you can load .m files this way or do anything you could do in the typical matlab command-line).

When you need to see the results (anything that is usually output to the command line in matlab), simply omit the semicolon after the command and use engOutputBuffer to capture the output.

Here is a simplified example from something I wrote:

#include "mat.h"
#include "engine.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define  BUFFER_SIZE 256

int main()

    Engine *ep;
    char buffer[BUFFER_SIZE];   // The buffer used to capture output.

    buffer[BUFFER_SIZE] = '\0'; /* Terminate the last character of the buffer. */

    if (!(ep = engOpen(NULL))) {
        fprintf(stderr, "\nCan't start MATLAB engine\n");
        return EXIT_FAILURE;

    if (engEvalString(ep, "load data/mymatfile.mat") != 0)
    printf("error evaluating expression\n");

    engOutputBuffer(ep, buffer, BUFFER_SIZE);

    /* No output returned. */
    if (engEvalString(ep, "p = 1+1;") != 0)
    printf("error evaluating expression\n");

    /* Output written to buffer- Note the omitted character (;). */
    if (engEvalString(ep, "q = p+1 "))
    printf("error evaluating expression\n");

    /* You will probably need to trim the whitespace in the buffer contents.
    I estimated +5 to pull out the prompt: ">>", but it depends on which version
    you have, for example, the student version displays "EDU >>\n". */
    printf("print the contents of the buffer:%s\n", buffer+5);

    /* Turn off output buffering. */
    engOutputBuffer(ep, NULL, 0);

    /* Close the engine. */



Once you have got a basic PHP extension compiled, throw the calls to the engine above into your extension and you can call MATLAB using the PHP function that you've defined in your extension.

Compiling the MATLAB API is probably the hardest part. Here are the contents of my Makefile (without the PHP extension code).

phpmat: phpmat.o
        gcc phpmat.o  
/usr/local/matlabR2009a/bin/glnx86/ -o phpmat

phpmat.o: phpmat.c
        gcc -c phpmat.c -I/usr/local/matlabR2009a/extern/include 
-L/usr/local/matlabR2009a/sys/os/glnx86 -L/usr/local/matlabR2009a/bin/glnx86

        rm *.o

You'll probably need to set your LD_LIBRARY_PATH before compiling/ calling the extension... However there are alternatives to this:


Is it possible to run matlab code from the web browser , I'm not expert in php. Can you kindly guide me step by step how to run matlab code in php? MATLAB has great integration with .NET. You need the MATLAB Compiler + the Builder NE toolbox to create a .NET assembly that you can run from a .NET-based web app. Some alternatives: You can do much the same thing using R (see this SO question), or possibly Python + numpy/scipy without all the licensing costs.

You should be able to invoke MatLab using passthru and include its output on the page.

See also MatLab command line options on Windows or on Unix.

Is it possible to run a matlab code on a web page?, Can I have the server, which will have Matlab, run the code using an It is easiest to share your analysis results from MATLAB via a web-page by using the​  web(url) opens the page specified by url in the MATLAB web browser. If url is an external site, web(url) opens the page in your system browser. If multiple browsers are open, the page displays in the one that was most recently used.

MATLAB has great integration with .NET. You need the MATLAB Compiler + the Builder NE toolbox to create a .NET assembly that you can run from a .NET-based web app.

Some alternatives: You can do much the same thing using R (see this SO question), or possibly Python + numpy/scipy without all the licensing costs.

Running MATLAB Programs on a webpage, I think this may be what you are looking for.​compiler/webapps/install-matlab-web-app-server.html  We are planning to create a website for a prediction system, where we need to get input from the user which in turn should run the matlab program (very similar to gui), and display the result in webpage.

Maybe this is the right solution:

edit containing these two pages:

Can I run MATLAB code on a server? - MATLAB Answers, Hi, i would love to develop a matlab program that could be use in a website. called AppReflector: Matlab users will run their Matlab GUI program on the server​,  I want to created a web site, look like a online calculator of a special formula that can input data, and output a graph. I know how to write the matlab code, but i don;t know how to put it into a web site. is there any video or article can teach me about that?

Your best bet might be using the matlab publish command, which allows you to create HTML from your matlab code. If you don't really need to execute the script live this will allow you to automatically generate your output and create image copies of your figures. After you generate the HTML and images you can simply upload them to your site.

publish command reference

A matlab program in a website - MATLAB Answers, If you don't have any license, don't worry; you can run just the MATLAB code well known site TutorialsPoint and all lot's of Terminals & IDEs all working online. There are two common ways to deteremine whether or not a MATLAB code can take advantage of parallelism without knowing anything about the code. The first to is run the code using 1 CPU-core and then do a second run using, say, 4 CPU-cores. Look to see if there is a significant difference in the execution time of the two codes.

How can I run MATLAB code in a web browser?, If your idea is to call Matlab functions direct from a html code, probably it will not can start in the web page a Java program that in turn runs the Matlab function. Control access to web apps by configuring MATLAB Web App Server to assign roles to individuals in your organization. App authors can create, upload, delete, and run web apps; end users can only run web apps.

How can we call MATLAB functions using web page? What are the , GNU Octave 3.6.4. Result. main.m; Support Function; Util Function; Extra File .​undefined. Execute. 1. run executes scripts not currently on the MATLAB path. However, you should use cd or addpath to navigate to or to add the appropriate folder, making a script executable by entering its name alone. scriptname can access any variables in the current workspace.

Execute MATLAB Script Online, The Octave syntax is largely compatible with Matlab. The Octave interpreter can be run in GUI mode, as a console, or invoked as part of a shell script. What If I Do Not Upgrade? If you do not update your MEX source code, you can still build your MEX files using the -compatibleArrayDims option. Use this flag to ensure the desired behavior across versions of MATLAB ®. If you build without the -compatibleArrayDims flag, then one or more of the following could occur:

  • thank you ... ill try it
  • is there a new technology for web UI for matlab where you can create interfaces like buttons, file upload button and text input?
  • I wouldn't bet much on it since it's discontinued.
  • But the page contains also two alternatives.
  • Made an edit to avoid a misunderstanding, sorry, was my fault.
  • Welcome to stackoverflow. Best practice is to include example code in your answer. An external link can break.