Reputation: 11
I'm new to JavaScript and is coding a simple webpage game using JavaScript for my research. People can play the game and some data will be collected. The collected data needs to be processed by MATLAB and the results will be returned to the JavaScript code. The JavaScript code will be run on client-side and the MATLAB will be in server-side.
How can a JavaScript program call functions in MATLAB and also receive the data from MATLAB? I searched online and found that MATLAB can be used as an Automation server and then be called by web applications (http://www.mathworks.com/help/matlab/matlab_external/call-matlab-functions-from-a-web-application.html).
The link gives an example using VBScript to call MATLAB files. However, I cannot find any resource for using JavaScript to call. What should I do with JavaScript? Besides, is there a way that JavaScript can interact with MATLAB?
Upvotes: 1
Views: 3716
Reputation: 939
I think that you can create a client programs using the RESTful API and JSON:
These steps were taken from this link: Example: Web-Based Bond Pricing Tool Using JavaScript
Upvotes: 0
Reputation: 3876
Your question is somewhat vague. It is a Web app, so there are two parties involved, the server side and the client side. Does MATLAB need to be called at the server side or the client side?
Assuming it is server side, there are multiple options
1) The COM automation server you mentioned works only if the server is running Windows, because COM is for Windows only.
2) Interface the server side code with C/C++ somehow, for example, using CGI, and use the C/C++ code to invoke the MATLAB Engine.
3) Use MATLAB Builder JA to convert MATLAB code to a JAR file, which can be invoked from your Java-based web app. Similarly, you can use MATLAB Builder EX to convert MATLAB code to a .NET assembly DLL, which can be invoked from your C# based (ASP.NET) web app.
4) Set up an MATLAB Production Server (MPS) and deploy code using MATLAB Compiler. The deployed MATLAB code can be invoked using Java, Python or .NET client code that run inside your server-side web app.
If it is client side JavaScript talking to MATLAB, I am afraid there is no easy way to make the two talk directly. MPS is still a possibility, but it will be via the server-side web app. Perhaps you can explore the possibility of using MATLAB Coder to convert the MATLAB code into C code and then use something like a transpiler to convert the C code into JavaScript code that can be run directly in the browser.
Upvotes: 2