Creating matlab modules for deployed matlab program
7 views (last 30 days)
Show older comments
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?
0 Comments
Answers (2)
Walter Roberson
on 17 Jul 2016
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.
Image Analyst
on 16 Jul 2016
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 Comments
Image Analyst
on 16 Jul 2016
Then don't use a switch and just pass the DLL name (string) into loadlibrary.
See Also
Categories
Find more on Language Support 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!