Creating matlab modules for deployed matlab program

6 ビュー (過去 30 日間)
John Alexander
John Alexander 2016 年 7 月 16 日
コメント済み: John Alexander 2016 年 7 月 17 日
Hi,
I compile my matlab application as a stand-alone console program, and everything works great. The program does a lot of database activity (via SQL) and number crunching. It reads a text file (an analysis script) line by line and executes the commands one at a time.
For example:
SQL SELECT * FROM table WHERE X=1
MATLAB FIND_AVERAGE
etc
The program reads the line, sees "SQL" and then executes the sql statement. If the program sees the word "MATLAB", it then uses a switch statement and executes the matlab function find_average.m
We are wanting to add "modular" matlab functions to the program. Without recompiling the main program, I'd like to be able to add new matlab functions (which would obviously have to be compiled some way).
For example, I want to add SuperCoolFunction.m so the following would trigger it.
MATLAB SuperCoolFunction
Since SuperCoolFunction.m wasn't in the original code when compiled and deployed, I want it to search for SuperCoolFunction.dll (or whatever extension an external matlab function would be). Then execute the function.
This way we can add functionality to the main program without having to recompile it.
Is this possible? Would I basically compile the individual functions as c++ dll, then use loadlibrary in the main program to scan for which libraries are available? Obviously if a function is requested and no library is found, I would handle the error.
Thoughts on this?

回答 (2 件)

Walter Roberson
Walter Roberson 2016 年 7 月 17 日
You probably already know this, but some of the other readers will not:
It is not possible to dynamically execute additional MATLAB code from inside code created from MATLAB Compiler. The interpreter is not present. It is not possible to just run() or create a function handle to an additional .m routine.
It is possible to loadlibrary() inside something compiled by MATLAB Compiler, but only in the @protofile form, not by supplying a .h . When the .h is supplied, MATLAB needs to be able to run a compiler to create a binary interface routine, which is something that is not supported by MATLAB Compiler.
You will probably need to use str2func to generate the function pointer from the prototype file. I am not sure how that could work at run time in a deployed object. I would not be astonished if it turned out that effectively all the prototype files had to exist at the time of compiling.
  1 件のコメント
John Alexander
John Alexander 2016 年 7 月 17 日
Thank you. I was coming to that conclusion. What I have been finding is that even if I could compile an additional matlab function as an independent entity, it would not have access to the "workspace" of the main program. As you said, the interpreter is not present.
The only choice I have is that every time I want to "add" a function, I have to recompile the main program. Not a big deal, just less than ideal.
The only alternative I can come up with is to have each of my "functions" be an exe. That would probably impact performance quite a bit, however, since it has to load the run time library for each call (and there will be many)

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


Image Analyst
Image Analyst 2016 年 7 月 16 日
The app can take command line arguments via the varargin cell array.
commandLine = varargin{1};
So pass in your word as a string, then you can use switch or whatever to take whatever action you want based on what was passed in.
switch commandLine
case 'SuperCoolFunction'
% Do something
case 'SuperCoolFunction2'
% Do something else
end
  2 件のコメント
John Alexander
John Alexander 2016 年 7 月 16 日
Yes, I do that already. That would require me to recompile the entire project should I want to add "SuperCoolFunction3" at a later point. What I'd like to do is compile just the function SuperCoolFunction3.m as an external function (like a dll, but I don't know if there are other options). When the main function gets "SuperCoolFunction3" it then looks for a dll named SuperCoolFunction3.dll, and then uses the function. That way I can create many smaller external functions and add them without having to recompile the main program. Does that make sense?
Image Analyst
Image Analyst 2016 年 7 月 16 日
Then don't use a switch and just pass the DLL name (string) into loadlibrary.

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

カテゴリ

Help Center および File ExchangeLanguage Support についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by