|

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. 

So, I hereby assume that you guys know about guide , how to make GUI and view callbacks. They all are already discussed in detail in the tutorial

Ladies and Gentlemen, make 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

More to follow!!

Posted by Unknown on 23:01. Filed under , , . You can follow any responses to this entry through the RSS 2.0. Feel free to leave a response

Labels

Recently Commented

Recently Added