如何从 .m 文件创建可执行的 .exe 文件
我想知道是否有一种方法可以在 MATLAB 中从“.m”文件创建“.exe”文件,这样它就可以在没有 MATLAB 的机器上运行(就像可以在 C、C++ 中完成一样)。
我知道编写 MATLAB 函数是一种方法,但我不确定它是否可以在没有 MATLAB 的机器上运行。
另外,我想隐藏我的代码,只创建一个可由用户使用自己的数据文件运行的脚本。
I was wondering if there is a way to create a '.exe' file from ' .m' file in MATLAB, such that it can be run in machine which does not have MATLAB (like it can be done in C, C++).
I know writing a MATLAB function is one way, but I am not sure if it can run in machine without MATLAB.
Also I would like to hide my code and just create a script which can be run by a user using his own data files.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
如果您安装了 MATLAB 编译器,则有一个用于编译的 GUI 选项。尝试
在命令行中输入。 Mathworks 在此视频教程中很好地记录了如何使用它:http ://www.mathworks.com/products/demos/compiler/deploytool/index.html
另外,如果您想包含用户输入(例如选择文件或目录),请查看
与
If you have MATLAB Compiler installed, there's a GUI option for compiling. Try entering
in the command line. Mathworks does a pretty good job documenting how to use it in this video tutorial: http://www.mathworks.com/products/demos/compiler/deploytool/index.html
Also, if you want to include user input such as choosing a file or directory, look into
for use in conjunction with
尝试:
另请参阅
help mcc
Try:
Also see
help mcc
如果您的代码更多的是数据分析例程(相对于可视化/GUI),请尝试 GNU Octave。它是免费的,并且它的许多功能都与 MATLAB 兼容。 (不是 100%,但可能是 99.5%。)
If your code is more of a data analysis routine (vs. visualization / GUI), try GNU Octave. It's free and many of its functions are compatible with MATLAB. (Not 100% but maybe 99.5%.)
解释说用 *.m 制作 *.exe(独立应用程序)的语法是:
例如:
将在当前目录中创建 file.exe。
explains that the syntax to make *.exe (Standalone Application) with *.m is:
For example:
will create file.exe in the curent directory.
过去可以使用旧版本的 Matlab 将 Matlab 编译为 C 语言。查看 Matlab 附带的其他工具。
最新的 Matlab 代码可以导出为 Java 的 jar 或 .Net Dll 等。然后您可以针对该库编写一个可执行文件 - 顺便说一下,它会被混淆。用户必须安装免费的 Matlab Runtime。
就像其他人提到的那样,mcc / mcc.exe 是将 matlab 代码转换为 C 代码的工具。
It used to be possible to compile Matlab to C with older versions of Matlab. Check out other tools that Matlab comes with.
Newest Matlab code can be exported as a Java's jar or a .Net Dll, etc. You can then write an executable against that library - it will be obfuscated by the way. The users will have to install a freely available Matlab Runtime.
Like others mentioned, mcc / mcc.exe is what you want to convert matlab code to C code.
编译 .m 文件(或多个文件)的“独立”方法需要目标(非 Matlab)平台上的一组 Matlab 发布的库(.dll)文件,以允许执行编译器生成的 .exe。
检查 MATLAB 主站点以了解其编译器产品及其限制。
The "StandAlone" method to compile .m file (or files) requires a set of Matlab published library (.dll) files on a target (non-Matlab) platform to allow execution of the compiler generated .exe.
Check MATLAB main site for their compiler products and their limitations.
我开发了一个非matlab软件,用于直接编译m文件( TMC 编译器)。这是 m 文件项目到 C 的开源转换器。编译器生成的 C 代码可以与提供的开源运行时库链接以生成独立的应用程序。该库实现了一组内置函数;线性代数运算使用 LAPACK 代码。可以通过文档中所述的自定义实现来扩展内置函数集。
I developed a non-matlab software for direct compilation of m-files (TMC Compiler). This is an open-source converter of m-files projects to C. The compiler produces the C code that may be linked with provided open-source run-time library to produce a stand-alone application. The library implements a set of build-in functions; the linear-algebra operations use LAPACK code. It is possible to expand the set of the build-in functions by custom implementation as described in the documentation.
Matlab 编译器 是执行此操作的标准方法。
mcc
是命令。运行程序需要Matlab Runtime;我不确定它是否可以直接与可执行文件集成。The Matlab Compiler is the standard way to do this.
mcc
is the command. The Matlab Runtime is required to run the programs; I'm not sure if it can be directly integrated with the executable or not.