Monday, 11 April 2011

Converting Matlab program to exe file

Sometimes we need to convert a .m extension matlab file to a executabe .exe file for various purposes.
To convert a matlab program to a executable file you have to open the program in the matlab editor.

Then in the command window write-
>>mbuild -setup
then a message will show in the command window:

Please choose your compiler for building standalone MATLAB applications:
Would you like mbuild to locate installed compilers [y]/n?

type y then command window will ask for selecting compiler....

 Select a compiler:
[1] Lcc-win32 C 2.4.1 in C:\PROGRA~1\MATLAB\R2008a\sys\lcc
[2] Microsoft Visual C++ 2008 in C:\Program Files\Microsoft Visual Studio 9.0

[0] None

Compiler: 
type : 1 or 2 to select one of the compiler.

then again have to verify your compiler when a message like below is shown in the window:
Please verify your choices:

Compiler: Microsoft Visual C++ 2008 
Location: C:\Program Files\Microsoft Visual Studio 9.0

Are these correct [y]/n?
.....type y again.
A message will appear like below:
Trying to update options file: C:\Users\bikash\AppData\Roaming\MathWorks\MATLAB\R2008a\compopts.bat
From template:              C:\PROGRA~1\MATLAB\R2008a\bin\win32\mbuildopts\msvc90compp.bat

Done . . .

Now write
>>mcc -m filename.m -o filename

if filename is guiButton then it will be >>mcc -m guiButton.m -o guiButton

then wait for a while. If >> will appear in the command window bellow the previous command line then your executable file has been created. Otherwise error will appear.

Have fun. I think this will help you a lot.

Image capturing in Matlab

Image capturing is very easy and friendly in matlab than any other language. To start the video preview window you have to write

obj = videoinput('winvideo');
preview(obj)

in the command window. Then press enter. Wow! you have just created a program which capture your image continuously like video.

To stop the preview you have to write :
stoppreview(obj)
in the command window and then have to press enter.
then the video preview will stop.

If you want to save the code then you have to open a .m file and save all the command in  that file. Remember if you write

preview(obj);
stoppreview(obj) ;

sequentially then no preview will appear. Because it will close as soon as it starts previewing.
You have to use definite delay time (how many times you want to keep camera on) between these two lines for previewing video.

Do fun with Matlab.