我可以在网站上运行MATLAB代码吗?

我有一个BE项目,其代码在MATLAB中,但我需要在网页上显示结果。 我想知道我是否可以直接在网站上运行我的代码? 如果没有,你能告诉我哪种语言会更好吗? 我想的可能是ASP,HTML和PHP。</ p>
</ div>

展开原文

原文

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.

dry69034
dry69034 谢谢......我会试一试
接近 11 年之前 回复

8个回答

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 <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, "
Can't start MATLAB engine
");
        return EXIT_FAILURE;
    }

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

    engOutputBuffer(ep, buffer, BUFFER_SIZE);

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

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


    /* 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 >>
". */
    printf("print the contents of the buffer:%s
", 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



您应该可以使用 passthru 并在页面上包含其输出。</ p>

另请参阅MatLab命令行选项在Windows上 /a>.


</ div>

展开原文

原文

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.

dongzhang6021
dongzhang6021 是否有一种用于matlab的Web UI新技术,您可以在其中创建按钮,文件上传按钮和文本输入等界面?
接近 4 年之前 回复



MATLAB与.NET有很好的集成。 您需要 MATLAB编译器 + Builder NE工具箱,用于创建可以从基于.NET的Web应用程序运行的.NET程序集。</ p> \ n

一些替代方案:您可以使用 R 做同样的事情(参见< a href =“https://stackoverflow.com/questions/1397097/r-web-application-introduction”>这个问题),或者可能是Python + numpy / scipy 。</ p>
</ div>

展开原文

原文

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.



也许这是正确的解决方案: http://www.mathworks.com/products/new_products/webserver_discontinued.html </ p>

编辑</ strong>包含 这两页:</ p>

http://www.mathworks。 com / products / netbuilder / </ p>

http: //www.mathworks.com/products/javabuilder/ </ p>
</ div>

展开原文

doujiang3997
doujiang3997 做了一个编辑,以避免误解,对不起,是我的错。
接近 11 年之前 回复
dongtuota3633
dongtuota3633 但该页面还包含两个备选方案。
接近 11 年之前 回复
doutong1890
doutong1890 因为它已经停止,我不会打赌它。
接近 11 年之前 回复



您最好的选择可能是使用matlab发布命令,该命令允许您从matlab代码创建HTML。 如果您不需要实时执行脚本,则可以自动生成输出并创建图形的图像副本。 生成HTML和图像后,您只需将它们上传到您的网站即可。 </ p>

发布命令参考 </ p>
</ div>

展开原文

原文

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



SaturnAPI 提供了 用于Matlab和Octave脚本的REST接口,因此您无需在自己的服务器上安装任何东西。 它甚至可以向您发送Base64编码的3D图。 这是演示。 下面的图表显示您可以通过HTTP调用中的 SaturnParams </ code>变量将输入传递给脚本。</ p>

</ a> </ p>

披露:我在SaturnAPI上工作</ p>
</ div>

展开原文

原文

SaturnAPI provides a REST interface for your Matlab and Octave scripts, so that you don't have to install anything on your own server. It can even send Base64 encoded 3D plots to you. Here is the demo. Below is a diagram showing that you can pass inputs to the script via the SaturnParams variable in the HTTP call.

enter image description here

Disclosure: I work on SaturnAPI

I use Matlab COM Automation Server via PHP, this runs a method that does some derivations:

$Matlab = new COM("Matlab.Application.Single");

$output = $Matlab->Execute("addpath '".dirname($_SERVER['SCRIPT_FILENAME'])."/'");

$output = $Matlab->Execute("[roots, dy, subsStr] = NewtonPrep('".$_REQUEST['eq']."')");

echo $output;

https://php.net/manual/en/book.com.php

https://www.mathworks.com/help/matlab/call-matlab-com-automation-server.html



如果 JavaScript </ strong>是一种可能的语言选择,那么MathWorks文件交换中的此工具箱( https://www.mathworks.com/matlabcentral/fileexchange/69973- generate-javascript-using-matlab-coder )可以将MATLAB函数编译成可以在浏览器中运行的JavaScript函数。</ p>
</ div>

展开原文

原文

If JavaScript is a possible language choice, then this toolbox on the MathWorks File Exchange (https://www.mathworks.com/matlabcentral/fileexchange/69973-generate-javascript-using-matlab-coder) can compile MATLAB functions into JavaScript functions that can be run in a browser.

dpb75177
dpb75177 欢迎来到stackoverflow。 最佳做法是在答案中包含示例代码。 外部链接可能会中断。
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐