I want to make a calculator in MATLAB GUIDE which stores the values of buttons when pressed in a variable and then add the values after each press and display the final value of variable in static text box after pressing the 'CALCULATE' push button. my gui looks like this
This is the code I have made so far. but it displays everything like a calculator. I only want a final answer to be displayed after addition without having to use the 'plus' button.
TIA
function varargout = untitled(varargin)gui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @untitled_OpeningFcn, ... 'gui_OutputFcn', @untitled_OutputFcn, ... 'gui_LayoutFcn', [], ... 'gui_Callback', []);if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1});endif nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});else gui_mainfcn(gui_State, varargin{:});endfunction untitled_OpeningFcn(hObject, eventdata, handles, varargin)handles.output = hObject;guidata(hObject, handles);function varargout = untitled_OutputFcn(hObject, eventdata, handles)varargout{1} = handles.output;function pushbutton3_Callback(hObject, eventdata, handles)set(handles.text2, 'string',[get(handles.text2, 'string'),'200']);function pushbutton4_Callback(hObject, eventdata, handles)set(handles.text2, 'string',[get(handles.text2, 'string'),'200']);function pushbutton5_Callback(hObject, eventdata, handles)set(handles.text2, 'string',[get(handles.text2, 'string'),'200']);function pushbutton6_Callback(hObject, eventdata, handles)set(handles.text2, 'string',[get(handles.text2, 'string'),'200']);function pushbutton7_Callback(hObject, eventdata, handles)set(handles.text2, 'string',[get(handles.text2, 'string'),'200']);function pushbutton8_Callback(hObject, eventdata, handles)set(handles.text2, 'string',[get(handles.text2, 'string'),'200']);function pushbutton9_Callback(hObject, eventdata, handles)set(handles.text2, 'string',[get(handles.text2, 'string'),'8']);function pushbutton10_Callback(hObject, eventdata, handles)set(handles.text2, 'string',num2str(eval(get(handles.text2, 'string'))));function pushbutton11_Callback(hObject, eventdata, handles)set(handles.text2, 'string',[get(handles.text2, 'string'),'+']);function pushbutton2_Callback(hObject, eventdata, handles)set(handles.text2, 'string',[get(handles.text2, 'string'),'21']);function pushbutton1_Callback(hObject, eventdata, handles)set(handles.text2, 'string',[get(handles.text2, 'string'),'12']);
Best Answer