to load Matlab executable once and keep calling the function many times?

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.

回答 (1 件)

Walter Roberson
Walter Roberson 2020 年 9 月 28 日
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 件のコメント

Suyash Naik
Suyash Naik 2020 年 9 月 28 日
Thanks Walter for your comment. I am able to run the executable using command line, but everytime it load the matlab model. Which takes time. I am not sure how many times the user will call this model so each time it loads it takes lots of time. cant i just load it and keep passing the arguments to fetch result?
Walter Roberson
Walter Roberson 2020 年 9 月 28 日
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.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeStartup and Shutdown についてさらに検索

製品

タグ

質問済み:

2020 年 9 月 28 日

コメント済み:

2020 年 9 月 28 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by