Looking for a way to compile a function for use natively in MATLAB

8 visualizzazioni (ultimi 30 giorni)
I have a function that I want protected, but I also want it to be usable natively in MATLAB. There is no need for a stand-alone app because the main purpose of this function is to be integrated into other MATLAB scripts and tools. If the function were self contained, I would probably (reluctantly) use pcode. However, the function actually makes use of a number of functions, but I do not want to distribute those as individual functions.
I have looked at the help for mex and mcc, but do not see a clear path to a native MATLAB implementation.
Is there a way for me to compile this one function (and all of the helpers it needs) into some form of compiled/protected function that can run natively in MATLAB?
The only solution I have identified as even being close to my goal, is to create pcode for all functions needed, and distribute those individual files.

Risposte (2)

Sean de Wolski
Sean de Wolski il 22 Mag 2015
pcode is really the only thing that does exactly what you want. There are some utilities on the File Exchange for batching pcode from lots of files.
One possible workaround: If the functions you are using are supported by MATLAB Coder, you could generate C-Code and mex it.

Walter Roberson
Walter Roberson il 22 Mag 2015
In the limited case where all of the functions are coded with "end" matching the "function", or all of the functions are coded without "end" matching the "function", then concatenate all of the files together and pcode() the result.
If you have a mix where some of the functions have the matching "end" and the others do not, then you cannot use this technique.
Most functions that do not have "end" matching "function" can be converted by just adding "end" to each function. However, this cannot be done to any function where a called routine does an assignin('caller') or equivalent that creates a variable where one did not exist before, but assignin that overwrites an existing variable is okay so there is usually a work-around. Simply adding an "end" also fails for routines that use load() of a .mat without specifying an output structure name and in so doing ends up creating variables that did not exist before. load() should always be re-written to assign to a structure name and then the needed values should be pulled out of the structure.
The case that has the most conversion difficulty is the case where the code is required to invoke a user-defined script that is permitted to create arbitrary variables.
And of course any code that creates variable names dynamically would need repairs.

Community Treasure Hunt

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

Start Hunting!

Translated by