views:

704

answers:

5

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 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. Thanks

+1  A: 

Try:

mcc -m yourfile

Also see help mcc

Andreas Bonini
Thanks , it works great, but not sure if it works in non matlab installed machines.
AP
+4  A: 

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.

phoebus
One thing to note - this is a toolbox that you have to pay extra for.
Andrew Shepherd
Good point. I wasn't sure because I've always worked on University installs that included it.
phoebus
The Matlab Compiler is pricey - it will set you back $5K.
Doresoom
...and deploytool provides an option to include the MCR library with your standalone executable.
Doresoom
A: 

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.

Hamish Grubijan
+1  A: 

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%.)

Jason S
99.32% of statistics are made up on the spot
Andreas Bonini
:-) -----------
Jason S
+2  A: 

If you have MATLAB Compiler installed, there's a GUI option for compiling. Try entering

deploytool

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

uigetfile % or uigetdir if you need every file in a directory

for use in conjunction with

guide
Doresoom

related questions