How to run external .m code in a MATLAB compiled application? [duplicate]

你。 提交于 2019-12-10 19:45:50

问题


I've got a MATLAB project, which I compile in order to have a single executable file, using MCC.

Then I would want to know if it's possible for an external programmer to execute some of his .m files within the .exe, without re-compiling the whole project.

The point is to provide an application in which other developpers could add their "plug-ins", written in MATLAB.

I've searched a way of running external .m files inside compiled MATLAB application (like this thread : Running an .m file from a MATLAB-compiled function) but it doesn't fit my purposes here, altough it's working fine using eval().

But this eval() "trick" isn't sufficient, as it doesn't allow to define new functions or classes. For instance, I would like external .m files to be new classes (inherited from compiled "interfaces" in the executable).

Is there a way to dynamically load .m files into a MATALB compiled executable ? (even if it needs a MATLAB licence to do such).

And/or is there some "undocumented MATLAB" that refers to this particular topic that I could investigate further ?

Regards,


回答1:


If you were able to create and distribute a compiled application that could execute arbitrary .m files, your users would be able to do pretty much anything MATLAB can do, but for free (even if that wasn't your intent).

Providing them with that capability (even if you intended something more innocent and useful) is against the license agreement for MATLAB Compiler, and MathWorks also put in place some technical restrictions to make it difficult to do so.

You might find a partial way around some of the technical restrictions, but if you give your users the ability to execute arbitrary m-code in a plugin, you'll be in breach of the license.

(Of course IANAL)




回答2:


I think that the only way is to do some system calls from your compiled function, like:

mFile2Launch='foo'; %%% or whatever input
system(['matlab -r "' mFile2Launch '"']);

or you can also use that more complicated line to make sure everything work well:

system(['matlab -nodesktop -nosplash -nodisplay -r "try, ' mFile2Launch '; end; quit"'])


来源:https://stackoverflow.com/questions/10882259/how-to-run-external-m-code-in-a-matlab-compiled-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!