How to convert a .m file to an .exe

182 views (last 30 days)
Ivan Mich
Ivan Mich on 2 May 2020
Answered: Ivan Mich on 6 May 2020
Hello,
I would like to ask something. How could I convert a matlab code (.m file) to an executable file (I mean to an .exe file)?
Could anyone help me?

Accepted Answer

Ivan Mich
Ivan Mich on 6 May 2020
Actually, I have tried these code and it works:
clc
clear
mcc -m file.m

More Answers (1)

Walter Roberson
Walter Roberson on 2 May 2020
You would use either MATLAB Compiler or MATLAB Coder.
MATLAB Compiler can compile most MATLAB (but not all!) to .exe. The resulting .exe does not require a MATLAB license to run. The .exe will be very close to the same speed as MATLAB itself... including taking a notable time to start up.
MATLAB Coder can transform some MATLAB to C or C++ code, that can then be compiled. The generated code does not require a MATLAB license to run. The generated code will be be optimized by your compiler, and in a fair number of cases will be faster than MATLAB itself. However, if your code made heavy use of vectorized mathematics, then there are cases where MATLAB itself would be faster, because the MATLAB Coder generated code might not call on the highly optimized libraries that MATLAB has access to. It is typical to need to make little adjustments to a notable portion of the MATLAB code to get it to work with MATLAB Coder. MATLAB Coder cannot compile graphics.
MATLAB Compiler is roughly the third-most expensive MATLAB product. MATLAB Coder is notably more expensive than MATLAB Compiler, and might be the most expensive product MATLAB offers. (I am not positive about that though, as I have not seen a quotation on the Automated Driving toolbox, which I understand is quite expensive.)
MATLAB Compiler is not available to Student licenses (or to Home licenses.) MATLAB Coder is available to Student licenses (but not to Home licenses.)

Categories

Find more on C Shared Library Integration 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!