How To Convert Matlab files into exe files


Converting .m files into stand alone applications


I don't take responsibility of this post. However I was able to transformed my Matlab GUI files into standalone executable files. Whats the benefit of doing all this ? You can still run your M-Files and applications without having Matlab installed in your system. That's what it does.

First of all, I am taking an example of a Calcultor.

Scientific Calculator in Matlab GUI
Only needs 4 lines of code !!
Today I am going to present you a scientific calculator build in MATLAB GUI. This calculator is capable of solving all the those scientific mathematics that matlab can do. And I was able to get this calculator programmed in 4 or 5 lines of code. In fact it was a matlab command 'eval()' that solved the problem. I really like this command. Couple of days ago, I posted a tutorial on MATLAB GUI and built a simple calculator. If you guys have not read that tutorial yet please go through that first else you will be in trouble because I will be taking shortcuts here.

How to make Calculator in Matlab GUI? (Tutorial)

A layout of your two line display calculator as shown below: :-




This is not very difficult in fact. Place two push buttons, two static texts and two edit texts ! And you are done. Rest you can make it more and more beautiful by playing with the fonts and calculators.

Call Backs

Look, we will be pressing Answer key and reset key only so we are concerned with callback of theses two buttons in this particular case only. Writing codes for the callback is again very easy. Right click the buttons and view the callbacks in M-file, generated. Lets come to the "Answer" and "Reset" callbacks  individually.

Answer Callback

x=get(handles.no1, 'String');
x=eval(x);
set(handles.no2, 'String', x);
guidata(hObject,handles);

 Believe me guys, your scientific calculator is ready with the magic of "eval()" command. What the code is doing? First of all its getting data from whatever user has entered. Since in my case the tag for input field is no1 therefore its using handles.no1. It is important to note here that get returns a string. In MATLAB there is a command eval() which solves or evaluate the expressions inside a string. The result thus obtained, is displayed using set command. Thats all the working of the code.

Reset Code:

set(handles.no1,'String', 0);
set(handles.no2,'String', 0);

Just to put a little "Shashka" in it, Reset is used here. Its quite evident that on pressing reset all the values will be reset that is "ZERO".
My Results
Here is, how I tested this scientific calculator in different ways. Few of the snaps are given below for  your motivation.

 

Another One:



Let's convert the calculator , which I showed you yesterday, into standalone executable files. Open Matlab command window. Type "mcc -m calculator.m". Calculator.m is the M - File for calculator and mcc -m is the Matlab command. You can explore more by typing "help mcc"

Typing mcc -m calculaor.m  will generate executable file in the same folder. The files genereated are :-
 exe file
asv file(s)
prg file(s)
c files(s)
log files
txt files
Now close Matlab and open calaculator.exe or any other exe file that you have generated. It would take sometime to open but will run with no difference. Its better you make a zip of above files. MRC installer must be installed in your system before you run it.Thanks!
0 Comments
Disqus
Fb Comments
Comments :

0 comments:

Post a Comment