to load Matlab executable once and keep calling the function many times?
2 views (last 30 days)
Show older comments
I have a requirement where in I need to load a matlab model and keep calling the function many times until user wants. I am trying to run the executable using Java. Once it is loaded i want to keep calling the function inside matlab model for 'n' number of times. is there any way to do it ? can someone suggest a good approach.
0 Comments
Answers (1)
Walter Roberson
on 28 Sep 2020
If you know the number ahead of time, perhaps pass it as a command line argument? At least if your executable is MATLAB and not generated from Simulink: I do not know anything about the command line arguments for executables generated from Simulink.
Command line arguments for MATLAB functions called from the command line, are received as character vectors; you would need to str2double() or equivalent to use them as numeric values.
For example,
myexe 5
then function myexe would receive '5' (the character vector), and not numeric 5.
2 Comments
Walter Roberson
on 28 Sep 2020
If you are talking about repeated execution of the entire command to invoke MATLAB, then MATLAB has to re-create the process every time, doing nearly as much initialization as would be done for an interactive MATLAB session.
Mathworks sells a product that can reduce the startup time -- MATLAB Production Server. I have never seen a price quoted for it, so I suspect it is probably over $US10000.
You could consider re-implementing in terms of using the MATLAB Automation Server; see https://www.mathworks.com/help/matlab/call-matlab-com-automation-server.html . That technology permits you to start up a MATLAB instance and send it commands and get back responses, with the single process staying around until you tell it to quit. However, I am not at all certain that you can compile that server into an executable (to avoid needing a MATLAB license); I have the suspicion that you cannot do that kind of compilation and so might need the server engine to be a "real" MATLAB.
See Also
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!