Calling .m script dynamically by a matlab executable
Show older comments
I have a Matlab executable. It should accept another .m script as an argument and execute it. This .m script can be changed before the execution of the executable. So cannot be included in the package during the build of executable. I tried using run command to run the script but got an error saying run requires valid MATLAB script. When ran the code, it ran perfectly fine without any error. Is there any other API that can serve this purpose? I am not an expert in Matlab. Kindly help me.
Answers (1)
Walter Roberson
on 30 Nov 2016
0 votes
run and eval and everything similar cannot be used for this situation.
Your compiled executable would have to start a new MATLAB session (the session would require a MATLAB license to run), or the compiled executable would have to communicate with a MATLAB session to request that commands be executed.
Starting a new MATLAB session can be done with system() or with the Java equivalents. On MS Windows it can also be done with activexserver()
Communicating with a MATLAB session with its cooperation can be done with TCP or UDP or various techniques such as shared memory segments. In MS Windows it can also be done with activexserver()
MATLAB has a complete remote session interface defined, the MATLAB engine API.
Note:*none* of these possibilities involves running the script or function in the same process, affecting the variables, changing settings and so on. At most you can communicate with a live MATLAB session, providing that it is all properly licensed.
Using MATLAB as a server requires appropriate MATLAB licenses. If the exact license depends on who will have access to the server. If this is all same department same building then a lower license is required than if there is wider access. If the public has access then you would need the most expensive kind of network license. If the time to start up a new MATLAB session is not acceptable then you should look at MATLAB Production Server.
To emphasize further: MATLAB Compiler, MATLAB Compiler SDK, and MATLAB Coder all generate in such a way that there is no more command line interpreter, so non-compiled scripts and functions literally cannot be processed except by talking to a MATLAB process.
Categories
Find more on Introduction to Installation and Licensing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!