# How to make matlab m-file executable?

Status
Not open for further replies.

#### neoaspilet11

##### Full Member level 5
Is there a way to do this? making executable files from matlab?

#### karim.elmahdy

##### Junior Member level 2
Yes of course,

you can use the MATLAB Compiler to make Stand-Alone Applications and here is a hint about how it works, I hope its enough for you.

The MATLAB Compiler, when invoked with the -m macro option, takes the input M-files and produces the required wrapper file suitable for a stand-alone application. Then, your C or C++ compiler compiles this code and links against the MCR, which is a stand-alone set of shared libraries that enable the execution of M-files. For example, to generate a stand-alone executable from the file example.m, use

Code:
[size=18]mcc -m example[/size]
where: mcc is the compliling command in MATLAB
-m is the macro option ( telling the compiler that it is .m file to be compiled)
example is the name of the .m file as you saved it.

Godd luck.

Added after 1 minutes:

Yes of course,

you can use the MATLAB Compiler to make Stand-Alone Applications and here is a hint about how it works, I hope its enough for you.

The MATLAB Compiler, when invoked with the -m macro option, takes the input M-files and produces the required wrapper file suitable for a stand-alone application. Then, your C or C++ compiler compiles this code and links against the MCR, which is a stand-alone set of shared libraries that enable the execution of M-files. For example, to generate a stand-alone executable from the file example.m, use

Code:
[size=18]mcc -m example[/size]
where: mcc is the compliling command in MATLAB
-m is the macro option ( telling the compiler that it is .m file to be compiled)
example is the name of the .m file as you saved it.

Godd luck.

### neoaspilet11

Points: 2
Helpful Answer Positive Rating

#### neoaspilet11

##### Full Member level 5
Very Good, Thank you very much for this wonderful information, Two more questions;

1.) I have not seen what filename should be use for the executable file. Is this automatically generated or I need to tell matlab what should be its filename? and how should I do it?

2.) What folder does the executable file is in?

I'll try this at home this night.
Thanks,
Jack

#### karim.elmahdy

##### Junior Member level 2
Dear Jack,

as shown in the command you give as a parameter the .m filename and it matlab creates the executable files in the same folder where the .m file is in and by the same name of the original .m filename.

Hope I've had helped enough.

Karim

### neoaspilet11

Points: 2
Helpful Answer Positive Rating

#### HMZ

##### Junior Member level 2
it is easy to ask it from matlab itself by
help mcc
and you'll get:
Make stand-alone C executable for myfun.m. Look for myfun.m in the directory /files/source, and put the resulting C files and executable in directory /files/target:
mcc -m -I /files/source -d /files/target myfun

Status
Not open for further replies.