Ask an expert. Trust the answer.

Your academic and career questions answered by verified experts

Expert Answer:

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):

http://devzone.zend.com/article/1021 

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 
#include 
#include 

#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. */
    engClose(ep);

    exit(0);

}

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/extern/lib/glnx86/version4.o 
/usr/local/matlabR2009a/bin/glnx86/libeng.so 
/usr/local/matlabR2009a/bin/glnx86/libmex.so -o phpmat

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

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

LD_LIBRARY_PATH=/usr/local/matlabR2009a/extern/lib/glnx86:/usr/local/matlabR2009a/bin/glnx86:/usr/local/matlabR2009a/sys/os/glnx86:$LD_LIBRARY_PATH

 

Why Matlabhelpers ?

Our Matlab assignment helpers for online MATLAB assignment help service take utmost care of your assignments by keeping the codes simple yet of high-quality. We offer the most reliable MATLAB solutions to students pursuing their Computer Science course from the Monash University, the University of Sydney, the University of New South Wales, the University of Melbourne; to name a few. Approach us today for best Matlab solutions online!

Our Comprehensive Matlab Assignment Help Services

Personalized Tutoring:Our team of MATLAB experts offers one-on-one tutoring sessions tailored to your specific needs. Whether you’re struggling with basic concepts or advanced algorithms, we provide clear, step-by-step guidance to help you understand and master MATLAB.

Assignment Assistance:Facing tight deadlines or complex assignments? We’re here to help! From initial problem analysis to code development and debugging, we offer full-spectrum support to ensure your assignments meet the highest standards.

Project Development: Need help with a research project? Our specialists can assist you in designing and implementing robust MATLAB solutions. We cover everything from project planning and data collection to coding, simulation, and result analysis.

Coursework Support: We provide comprehensive support for your coursework, helping you understand lectures, complete lab exercises, and prepare for exams. Our goal is to ensure you grasp the core principles and practical applications of MATLAB.

Thesis and Dissertation Guidance:Writing a thesis or dissertation? Our experts can assist you in incorporating MATLAB for data analysis, modeling, and simulation. We help you develop a strong methodological framework and ensure your research stands out.

whatsApp order on matlabhelpers.com

telegram order on matlabsolutions.com