0

As stated, I have a NodeJS server and some .m files with scripts that I need to run (maybe with some .dat files as arguments as well) and display the results on a web page.

I am wondering how should I handle this. Can I run .m scripts from JS directly? Should I compile the scripts first? If so, any specific compiler that I should use?

EDIT: I don't (and won't) have MATLAB or Octave installed on the server.

user3105173
  • 435
  • 4
  • 15
  • You can run your .m files as a Node.js subprocess and simply intercept the subprocess' stdout How to run subprocess in Node.js described here (You can also use third-party modules such as execa) How to run .m file via the terminal described in [this](https://stackoverflow.com/a/6717782/10160550) answer – Porbs Jul 31 '18 at 12:43
  • I probably should have mentioned this in the OP, but I don't have MATLAB or Octave installed on the server. Is it still possible to run the .m files? – user3105173 Jul 31 '18 at 12:50
  • 2
    you need to run .m files without MATLAB? I don't think that it's possible. You can use an external API to obtain results of .m files processing, but in this case your web service will be just a kind of a alternative view of existing web service – Porbs Jul 31 '18 at 14:43
  • you _can_ convert octave code to C++ code to obtain a standalone binary executable, though it's not necessarily straightforward. is this what you had in mind? – Tasos Papastylianou Aug 01 '18 at 13:38

2 Answers2

1

Mathworks freely offers a MATLAB runtime environent (download here). You do need to compile your program with a Matlab compiler (normally on the same OS as you intend to run the program on). Files can be compiled with the program, just make sure you locally reference the files (no absolute paths)

s maz
  • 31
  • 3
  • But keep in mind that the compiler is quite expensive and costs several k$ or k€ and the runtime installation is about 1-3 GB on the harddisk. – tardis Aug 17 '18 at 05:56
-1

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. You may have to load the .DAT file in JavaScript and pass the data to the compiled function as an input.