Simple Calculator using MATLAB
How to create Simple Calculator using MATLAB - Matlab for beginners
GUI Video is below the code
function varargout = mycaltest(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @mycaltest_OpeningFcn, ...
'gui_OutputFcn', @mycaltest_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
function mycaltest_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
function varargout = mycaltest_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function four_Callback(hObject, eventdata, handles)
str = get(handles.ans,'String');
str = strcat(str,'4');
set(handles.ans,'String',str);
function one_Callback(hObject, eventdata, handles)
str = get(handles.ans,'String');
str = strcat(str,'1');
set(handles.ans,'String',str);
function point_Callback(hObject, eventdata, handles)
str = get(handles.ans,'String');
str = strcat(str,'.');
set(handles.ans,'String',str);
function seven_Callback(hObject, eventdata, handles)
str = get(handles.ans,'String');
str = strcat(str,'7');
set(handles.ans,'String',str);
function zero_Callback(hObject, eventdata, handles)
str = get(handles.ans,'String');
str = strcat(str,'0');
set(handles.ans,'String',str);
function two_Callback(hObject, eventdata, handles)
str = get(handles.ans,'String');
str = strcat(str,'2');
set(handles.ans,'String',str);
function five_Callback(hObject, eventdata, handles)
str = get(handles.ans,'String');
str = strcat(str,'5');
set(handles.ans,'String',str);
function eight_Callback(hObject, eventdata, handles)
str = get(handles.ans,'String');
% it will take the value of ans (ans is our static text
str = strcat(str,'8');
%it will concatinate 8 with the privues string
set(handles.ans,'String',str);
%and it will again set the new value to ans static text
function equal_Callback(hObject, eventdata, handles)
str = get(handles.ans,'String');
%it will take the value
str = eval(str);
%the eval function solve the string or evalutae the string
set(handles.ans1,'String',str);
%after evaluation the ans was
%shown in the above static text ans1.
function three_Callback(hObject, eventdata, handles)
str = get(handles.ans,'String');
str = strcat(str,'3');
set(handles.ans,'String',str);
function six_Callback(hObject, eventdata, handles)
str = get(handles.ans,'String');
str = strcat(str,'6');
set(handles.ans,'String',str);
function nine_Callback(hObject, eventdata, handles)
str = get(handles.ans,'String');
str = strcat(str,'9');
set(handles.ans,'String',str);
function div_Callback(hObject, eventdata, handles)
str = get(handles.ans,'String');
str = strcat(str,'/');
set(handles.ans,'String',str);
function add_Callback(hObject, eventdata, handles)
str = get(handles.ans,'String');
str = strcat(str,'+');
set(handles.ans,'String',str);
function sub_Callback(hObject, eventdata, handles)
str = get(handles.ans,'String');
str = strcat(str,'-');
set(handles.ans,'String',str);
function mul_Callback(hObject, eventdata, handles)
str = get(handles.ans,'String');
str = strcat(str,'*');
set(handles.ans,'String',str);
function clear_Callback(hObject, eventdata, handles)
set(handles.ans1,'String','');
set(handles.ans,'String','');
Read Also:
Post a Comment