MatLAB GUI Calculator

Koray Efe Yağmur
6 min readMay 2, 2021

Hello dear reader, today (02.05.2021) ı learn some skills in MatLAB. The skills were about GUI. Today ı write some basic codes in MatLAB for make a basic calculator. Let you check there;

02.05.2021 13:16 C:\…\mak813week10odev2.m 1 of 7

function varargout = mak813week10odev2(varargin)

% MAK813WEEK10ODEV2 MATLAB code for mak813week10odev2.fig

% MAK813WEEK10ODEV2, by itself, creates a new MAK813WEEK10ODEV2

or raises the existing

% singleton*.

%

% H = MAK813WEEK10ODEV2 returns the handle to a new

MAK813WEEK10ODEV2 or the handle to

% the existing singleton*.

%

% MAK813WEEK10ODEV2(‘CALLBACK’,hObject,eventData,handles,…)

calls the local

% function named CALLBACK in MAK813WEEK10ODEV2.M with the given

input arguments.

%

% MAK813WEEK10ODEV2(‘Property’,’Value’,…) creates a new

MAK813WEEK10ODEV2 or raises the

% existing singleton*. Starting from the left, property value

pairs are

% applied to the GUI before mak813week10odev2_OpeningFcn gets

called. An

% unrecognized property name or invalid value makes property

application

% stop. All inputs are passed to mak813week10odev2_OpeningFcn

via varargin.

%

% *See GUI Options on GUIDE’s Tools menu. Choose “GUI allows

only one

% instance to run (singleton)”.

%

% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help mak813week10odev2

% Last Modified by GUIDE v2.5 02-May-2021 13:13:05

% Begin initialization code — DO NOT EDIT

gui_Singleton = 1;

gui_State = struct(‘gui_Name’, mfilename, …

‘gui_Singleton’, gui_Singleton, …

‘gui_OpeningFcn’, @mak813week10odev2_OpeningFcn,

‘gui_OutputFcn’, @mak813week10odev2_OutputFcn, …

‘gui_LayoutFcn’, [] , …

02.05.2021 13:16 C:\…\mak813week10odev2.m 2 of 7

‘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

% End initialization code — DO NOT EDIT

% — — Executes just before mak813week10odev2 is made visible.

function mak813week10odev2_OpeningFcn(hObject, eventdata, handles,

varargin)

% This function has no output args, see OutputFcn.

% hObject handle to figure

% eventdata reserved — to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% varargin command line arguments to mak813week10odev2 (see

VARARGIN)

% Choose default command line output for mak813week10odev2

handles.output = hObject;

% Update handles structure

guidata(hObject, handles);

% UIWAIT makes mak813week10odev2 wait for user response (see UIRESUME)

% uiwait(handles.figure1);

% — — Outputs from this function are returned to the command line.

function varargout = mak813week10odev2_OutputFcn(hObject, eventdata,

handles)

% varargout cell array for returning output args (see VARARGOUT);

% hObject handle to figure

% eventdata reserved — to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure

varargout{1} = handles.output;

02.05.2021 13:16 C:\…\mak813week10odev2.m 3 of 7

function altpanel_Callback(hObject, eventdata, handles)

% hObject handle to altpanel (see GCBO)

% eventdata reserved — to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,’String’) returns contents of altpanel as text

% str2double(get(hObject,’String’)) returns contents of

altpanel as a double

% — — Executes during object creation, after setting all properties.

function altpanel_CreateFcn(hObject, eventdata, handles)

% hObject handle to altpanel (see GCBO)

% eventdata reserved — to be defined in a future version of MATLAB

% handles empty — handles not created until after all CreateFcns

called

% Hint: edit controls usually have a white background on Windows.

% See ISPC and COMPUTER.

if ispc && isequal(get(hObject,’BackgroundColor’), get

(0,’defaultUicontrolBackgroundColor’))

set(hObject,’BackgroundColor’,’white’);

end

% — — Executes on button press in yedi.

function yedi_Callback(hObject, eventdata, handles)

% hObject handle to yedi (see GCBO)

% eventdata reserved — to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

a= get(handles.altpanel,’String’);

set(handles.altpanel,’String’,strcat(a,’7'));

% — — Executes on button press in sekiz.

function sekiz_Callback(hObject, eventdata, handles)

% hObject handle to sekiz (see GCBO)

% eventdata reserved — to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

a= get(handles.altpanel,’String’);

set(handles.altpanel,’String’,strcat(a,’8'));

02.05.2021 13:16 C:\…\mak813week10odev2.m 4 of 7

% — — Executes on button press in dokuz.

function dokuz_Callback(hObject, eventdata, handles)

% hObject handle to dokuz (see GCBO)

% eventdata reserved — to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

a= get(handles.altpanel,’String’);

set(handles.altpanel,’String’,strcat(a,’9'));

% — — Executes on button press in bolme.

function bolme_Callback(hObject, eventdata, handles)

% hObject handle to bolme (see GCBO)

% eventdata reserved — to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

a= get(handles.altpanel,’String’);

set(handles.altpanel,’String’,strcat(a,’/’));

% — — Executes on button press in dort.

function dort_Callback(hObject, eventdata, handles)

% hObject handle to dort (see GCBO)

% eventdata reserved — to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

a= get(handles.altpanel,’String’);

set(handles.altpanel,’String’,strcat(a,’4'));

% — — Executes on button press in bes.

function bes_Callback(hObject, eventdata, handles)

% hObject handle to bes (see GCBO)

% eventdata reserved — to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

a= get(handles.altpanel,’String’);

set(handles.altpanel,’String’,strcat(a,’5'));

% — — Executes on button press in alti.

function alti_Callback(hObject, eventdata, handles)

% hObject handle to alti (see GCBO)

% eventdata reserved — to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

a= get(handles.altpanel,’String’);

set(handles.altpanel,’String’,strcat(a,’6'));

02.05.2021 13:16 C:\…\mak813week10odev2.m 5 of 7

% — — Executes on button press in carpma.

function carpma_Callback(hObject, eventdata, handles)

% hObject handle to carpma (see GCBO)

% eventdata reserved — to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

a= get(handles.altpanel,’String’);

set(handles.altpanel,’String’,strcat(a,’*’));

% — — Executes on button press in bir.

function bir_Callback(hObject, eventdata, handles)

% hObject handle to bir (see GCBO)

% eventdata reserved — to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

a= get(handles.altpanel,’String’);

set(handles.altpanel,’String’,strcat(a,’1'));

% — — Executes on button press in iki.

function iki_Callback(hObject, eventdata, handles)

% hObject handle to iki (see GCBO)

% eventdata reserved — to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

a= get(handles.altpanel,’String’);

set(handles.altpanel,’String’,strcat(a,’2'));

% — — Executes on button press in uc.

function uc_Callback(hObject, eventdata, handles)

% hObject handle to uc (see GCBO)

% eventdata reserved — to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

a= get(handles.altpanel,’String’);

set(handles.altpanel,’String’,strcat(a,’3'));

% — — Executes on button press in cikarma.

function cikarma_Callback(hObject, eventdata, handles)

% hObject handle to cikarma (see GCBO)

% eventdata reserved — to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

a= get(handles.altpanel,’String’);

02.05.2021 13:16 C:\…\mak813week10odev2.m 6 of 7

set(handles.altpanel,’String’,strcat(a,’-’));

% — — Executes on button press in sifir.

function sifir_Callback(hObject, eventdata, handles)

% hObject handle to sifir (see GCBO)

% eventdata reserved — to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

a= get(handles.altpanel,’String’);

set(handles.altpanel,’String’,strcat(a,’0'));

% — — Executes on button press in artieksi.

function artieksi_Callback(hObject, eventdata, handles)

% hObject handle to artieksi (see GCBO)

% eventdata reserved — to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

a= get(handles.altpanel,’String’);

set(handles.altpanel,’String’,strcat(a,’-’));

% — — Executes on button press in virgul.

function virgul_Callback(hObject, eventdata, handles)

% hObject handle to virgul (see GCBO)

% eventdata reserved — to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

a= get(handles.altpanel,’String’);

set(handles.altpanel,’String’,strcat(a,’,’));

% — — Executes on button press in toplama.

function toplama_Callback(hObject, eventdata, handles)

% hObject handle to toplama (see GCBO)

% eventdata reserved — to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

a= get(handles.altpanel,’String’);

set(handles.altpanel,’String’,strcat(a,’+’));

% — — Executes on button press in sil.

function sil_Callback(hObject, eventdata, handles)

% hObject handle to sil (see GCBO)

% eventdata reserved — to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

02.05.2021 13:16 C:\…\mak813week10odev2.m 7 of 7

set(handles.altpanel,’String’,’’);

% — — Executes on button press in sonuc.

function sonuc_Callback(hObject, eventdata, handles)

% hObject handle to sonuc (see GCBO)

% eventdata reserved — to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

sonuc= get(handles.altpanel,’String’);

sonuc= str2num(sonuc);

sonuc= num2str(sonuc);

set(handles.ustpanel,’String’,sonuc);

set(handles.altpanel,’String’,’’);

% — — Executes on button press in ans.

function ans_Callback(hObject, eventdata, handles)

% hObject handle to ans (see GCBO)

% eventdata reserved — to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

veri=get(handles.ustpanel,’String’);

veri2=get(handles.altpanel,’String’);

set(handles.altpanel,’String’,strcat(veri2,veri));

% — — Executes on button press in backspace.

function backspace_Callback(hObject, eventdata, handles)

% hObject handle to backspace (see GCBO)

% eventdata reserved — to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

veri=get(handles.altpanel,’String’);

veri(end)=’’;

set(handles.altpanel,’String’,veri);

--

--

Koray Efe Yağmur

Im a Robotic and Mechanical Engineer. I will write some codes about robotics and share them with you. Just follow me!