Anda di halaman 1dari 45

Nama : Dewi Kurnia

Nim : 60400118035

TUGAS PROGRAM GUI

Tugas Wajib Hal 34

1. Membuat Program GUI hitung trigonometri


a. Buat komponen GUI dan masukkan fungsinya

b. Agar tombol buat grafik dapat berfungsi, klik buat grafik lalu pilih view
callback lalu klik callback dan akan muncul ke script

Muncul ke script dan tambahkan fungsi persamaan di file script pada baris
81,94, 107, 140
Line 81:

set(handles.radiobutton2,'value',0);
pilih=1
handles.pilih=pilih;
guidata(hObject,handles)
Line 94:

set(handles.radiobutton1,'value',0);
pilih=2
handles.pilih=pilih;
guidata(hObject,handles)
Line 107

indeks=get(handles.eksekusi,'value');%mengambil nilai
if indeks==1 %jika menekan 1
T=1; %maka T=1
else if indeks==2 %jika menekan 2
T=2; %maka T=2, dst
else if indeks==3
T=3;
else if indeks==4
T=4;
end
end
end
end
A=str2num(get(handles.edit1,'string'));
r=str2num(get(handles.edit1,'string'));
x=-10:0.1:10; %membangkitkan sumbu-x
pilih=handles.pilih
switch handles.pilih
case 1 %jika radiobutton1 yang ditekan
y=A*sin(T*x*r); %maka menghitung nilai sin
case 2 %jika radiobutton2 yang ditekan
y=A*cos(T*x*r); %maka menghitung nilai cos
end
axes(handles.axes1);
a=0; %membuat garis sumbu_x dan sumbu_y
plot(x,y,'r',a,x,'b',x,a,'b');
grid on
Line 140:

set(handles.edit1,'string',''); %mengosongkan string


pada edit1
set(handles.edit4,'string',''); %mengosongkan string
pada edit4
axes(handles.axes1);
plot(0); %memberikan gambar pada axes
c. Pilih Run. Lalu masukkan nilai Amplitudo=25, Phase=10, sudut=30 lalu klik
Hasil

Hasil scriptnya:

function varargout = trigono(varargin)


% TRIGONO M-file for trigono.fig
% TRIGONO, by itself, creates a new TRIGONO or raises the
existing
% singleton*.
%
% H = TRIGONO returns the handle to a new TRIGONO or the
handle to
% the existing singleton*.
%
% TRIGONO('CALLBACK',hObject,eventData,handles,...) calls
the local
% function named CALLBACK in TRIGONO.M with the given
input arguments.
%
% TRIGONO('Property','Value',...) creates a new TRIGONO
or raises the
% existing singleton*. Starting from the left, property
value pairs are
% applied to the GUI before trigono_OpeningFcn gets
called. An
% unrecognized property name or invalid value makes
property application
% stop. All inputs are passed to trigono_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 trigono


% Last Modified by GUIDE v2.5 08-Nov-2010 01:28:44

% Begin initialization code - DO NOT EDIT


gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @trigono_OpeningFcn, ...
'gui_OutputFcn', @trigono_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
% End initialization code - DO NOT EDIT

% --- Executes just before trigono is made visible.


function trigono_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 trigono (see VARARGIN)

% Choose default command line output for trigono


handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

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


% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command


line.
function varargout = trigono_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;

% --- Executes on button press in radiobutton1.


function radiobutton1_Callback(hObject, eventdata, handles)
% hObject handle to radiobutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)
set(handles.radiobutton2,'value',0);
pilih=1
handles.pilih=pilih;
guidata(hObject,handles)

% Hint: get(hObject,'Value') returns toggle state of


radiobutton1

% --- Executes on button press in radiobutton2.


function radiobutton2_Callback(hObject, eventdata, handles)
% hObject handle to radiobutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)
set(handles.radiobutton1,'value',0);
pilih=2
handles.pilih=pilih;
guidata(hObject,handles)

% Hint: get(hObject,'Value') returns toggle state of


radiobutton2

% --- Executes on button press in eksekusi.


function eksekusi_Callback(hObject, eventdata, handles)
% hObject handle to eksekusi (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)
indeks=get(handles.eksekusi,'value');%mengambil nilai
if indeks==1 %jika menekan 1
T=1; %maka T=1
else if indeks==2 %jika menekan 2
T=2; %maka T=2, dst
else if indeks==3
T=3;
else if indeks==4
T=4;
end
end
end
end
A=str2num(get(handles.edit1,'string'));
r=str2num(get(handles.edit1,'string'));
x=-10:0.1:10; %membangkitkan sumbu-x
pilih=handles.pilih
switch handles.pilih
case 1 %jika radiobutton1 yang ditekan
y=A*sin(T*x*r); %maka menghitung nilai sin
case 2 %jika radiobutton2 yang ditekan
y=A*cos(T*x*r); %maka menghitung nilai cos
end
axes(handles.axes1);
a=0; %membuat garis sumbu_x dan sumbu_y
plot(x,y,'r',a,x,'b',x,a,'b');
grid on

% --- Executes on button press in pushbutton2.


function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)
set(handles.edit1,'string',''); %mengosongkan string pada
edit1
set(handles.edit4,'string',''); %mengosongkan string pada
edit4
axes(handles.axes1);
plot(0); %memberikan gambar pada axes

% --- Executes on button press in Close.


function Close_Callback(hObject, eventdata, handles)
% hObject handle to Close (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)
close

function edit1_Callback(hObject, eventdata, handles)


% hObject handle to edit1 (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 edit1 as


text
% str2double(get(hObject,'String')) returns contents of
edit1 as a double

% --- Executes during object creation, after setting all


properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (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

function edit4_Callback(hObject, eventdata, handles)


% hObject handle to edit4 (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 edit4 as
text
% str2double(get(hObject,'String')) returns contents of
edit4 as a double

% --- Executes during object creation, after setting all


properties.
function edit4_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit4 (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

function edit5_Callback(hObject, eventdata, handles)


% hObject handle to edit5 (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 edit5 as


text
% str2double(get(hObject,'String')) returns contents of
edit5 as a double

% --- Executes during object creation, after setting all


properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit5 (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
2. Membuat Program GUI aplikasi fisika tentang kasus fisika dalam kehidupan
sehari-hari
a. Buat komponen GUI dan masukkan fungsinya
b. Agar tombol buat grafik dapat berfungsi, klik buat grafik lalu pilih view
callback lalu klik callback dan akan muncul ke script

Muncul ke script dan tambahkan fungsi persamaan di file script pada baris
81, 107, 133, 182, dan 190

Line 81:

F=str2num(get(handles.edit1,'String'));
handles.F=F;
guidata(hObject,handles)
Line 107

m=str2num(get(handles.edit2,'String'));
handles.m=m;
guidata(hObject,handles);
Line 133

t=str2num(get(handles.edit3,'String'));
handles.t=t;
guidata(hObject,handles);
Line 159

v=str2num(get(handles.edit4,'String'));
handles.v=v;
guidata(hObject,handles);
Line 231

F=handles.F;
m=handles.m;
v=handles.v;
t=handles.t;
I=F*t;
p=m*v;
set(handles.edit5,'string',I);
set(handles.edit6,'string',p);
Line 245

close
c. Pilih Run. Lalu masukkan nilai Gaya=40, Massa=25, t=15, v=17 lalu klik Hasil

Hasil scriptnya:
function varargout = untitled1(varargin)
% UNTITLED1 M-file for untitled1.fig
% UNTITLED1, by itself, creates a new UNTITLED1 or raises
the existing
% singleton*.
%
% H = UNTITLED1 returns the handle to a new UNTITLED1 or
the handle to
% the existing singleton*.
%
% UNTITLED1('CALLBACK',hObject,eventData,handles,...)
calls the local
% function named CALLBACK in UNTITLED1.M with the given
input arguments.
%
% UNTITLED1('Property','Value',...) creates a new
UNTITLED1 or raises the
% existing singleton*. Starting from the left, property
value pairs are
% applied to the GUI before untitled1_OpeningFcn gets
called. An
% unrecognized property name or invalid value makes
property application
% stop. All inputs are passed to untitled1_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 untitled1

% Last Modified by GUIDE v2.5 08-Nov-2010 03:48:53

% Begin initialization code - DO NOT EDIT


gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @untitled1_OpeningFcn,
...
'gui_OutputFcn', @untitled1_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
% End initialization code - DO NOT EDIT

% --- Executes just before untitled1 is made visible.


function untitled1_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 untitled1 (see
VARARGIN)
% Choose default command line output for untitled1
handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

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


% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command


line.
function varargout = untitled1_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;

function edit1_Callback(hObject, eventdata, handles)


% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)
F=str2num(get(handles.edit1,'String'));
handles.F=F;
guidata(hObject,handles)

% Hints: get(hObject,'String') returns contents of edit1 as


text
% str2double(get(hObject,'String')) returns contents of
edit1 as a double

% --- Executes during object creation, after setting all


properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (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

function edit5_Callback(hObject, eventdata, handles)


% hObject handle to edit5 (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 edit5 as


text
% str2double(get(hObject,'String')) returns contents of
edit5 as a double

% --- Executes during object creation, after setting all


properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit5 (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

function edit6_Callback(hObject, eventdata, handles)


% hObject handle to edit6 (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 edit6 as


text
% str2double(get(hObject,'String')) returns contents of
edit6 as a double

% --- Executes during object creation, after setting all


properties.
function edit6_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit6 (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 pushbutton1.


function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)
F=handles.F;
m=handles.m;
v=handles.v;
t=handles.t;
I=F*t;
p=m*v;
set(handles.edit5,'string',I);
set(handles.edit6,'string',p);

% --- Executes on button press in pushbutton2.


function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)
close

function edit2_Callback(hObject, eventdata, handles)


% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)
m=str2num(get(handles.edit2,'String'));
handles.m=m;
guidata(hObject,handles);

% Hints: get(hObject,'String') returns contents of edit2 as


text
% str2double(get(hObject,'String')) returns contents of
edit2 as a double

% --- Executes during object creation, after setting all


properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (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

function edit3_Callback(hObject, eventdata, handles)


% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)
t=str2num(get(handles.edit3,'String'));
handles.t=t;
guidata(hObject,handles);
% Hints: get(hObject,'String') returns contents of edit3 as
text
% str2double(get(hObject,'String')) returns contents of
edit3 as a double

% --- Executes during object creation, after setting all


properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (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

function edit4_Callback(hObject, eventdata, handles)


% hObject handle to edit4 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)
v=str2num(get(handles.edit4,'String'));
handles.v=v;
guidata(hObject,handles);

% Hints: get(hObject,'String') returns contents of edit4 as


text
% str2double(get(hObject,'String')) returns contents of
edit4 as a double

% --- Executes during object creation, after setting all


properties.
function edit4_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit4 (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
3. Membuat Program GUI hitung nilai IPK Mahasiswa
a. Buat komponen GUI dan masukkan fungsinya
b. Agar tombol buat grafik dapat berfungsi, klik buat grafik lalu pilih view
callback lalu klik callback dan akan muncul ke script

Muncul ke script dan tambahkan fungsi persamaan di file script pada baris
81, 107, 133, 182, dan 190

Line 81:

ips1=str2num(get(handles.edit1,'String'));
handles.ips1=ips1;
guidata(hObject,handles)
Line 107:
ips2=str2num(get(handles.edit2,'String'));
handles.ips2=ips2;
guidata(hObject,handles)
Line 133:

ips3=str2num(get(handles.edit3,'String'));
handles.ips3=ips3;
guidata(hObject,handles)
Line 182:

ips1=handles.ips1;
ips2=handles.ips2;
ips3=handles.ips3;
ipk=(ips1+ips2+ips3)/3;
set(handles.edit4,'String',ipk)
Line 190

close
c. Pilih Run. Lalu masukkan nilai IPS 1, IPS 2, dan IPS 3 kemudian Klik Hasilnya

Hasil scriptnya:
function varargout = untitled(varargin)
% UNTITLED M-file for untitled.fig
% UNTITLED, by itself, creates a new UNTITLED or raises
the existing
% singleton*.
%
% H = UNTITLED returns the handle to a new UNTITLED or
the handle to
% the existing singleton*.
%
% UNTITLED('CALLBACK',hObject,eventData,handles,...)
calls the local
% function named CALLBACK in UNTITLED.M with the given
input arguments.
%
% UNTITLED('Property','Value',...) creates a new UNTITLED
or raises the
% existing singleton*. Starting from the left, property
value pairs are
% applied to the GUI before untitled_OpeningFcn gets
called. An
% unrecognized property name or invalid value makes
property application
% stop. All inputs are passed to untitled_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 untitled

% Last Modified by GUIDE v2.5 08-Nov-2010 00:16:26

% Begin initialization code - DO NOT EDIT


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});
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 untitled is made visible.


function untitled_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 untitled (see VARARGIN)

% Choose default command line output for untitled


handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

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


% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command


line.
function varargout = untitled_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;

function edit1_Callback(hObject, eventdata, handles)


% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)
ips1=str2num(get(handles.edit1,'String'));
handles.ips1=ips1;
guidata(hObject,handles)

% Hints: get(hObject,'String') returns contents of edit1 as


text
% str2double(get(hObject,'String')) returns contents of
edit1 as a double

% --- Executes during object creation, after setting all


properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (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

function edit2_Callback(hObject, eventdata, handles)


% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)
ips2=str2num(get(handles.edit2,'String'));
handles.ips2=ips2;
guidata(hObject,handles)

% Hints: get(hObject,'String') returns contents of edit2 as


text
% str2double(get(hObject,'String')) returns contents of
edit2 as a double
% --- Executes during object creation, after setting all
properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (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

function edit3_Callback(hObject, eventdata, handles)


% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)
ips3=str2num(get(handles.edit3,'String'));
handles.ips3=ips3;
guidata(hObject,handles)

% Hints: get(hObject,'String') returns contents of edit3 as


text
% str2double(get(hObject,'String')) returns contents of
edit3 as a double

% --- Executes during object creation, after setting all


properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (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

function edit4_Callback(hObject, eventdata, handles)


% hObject handle to edit4 (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 edit4 as


text
% str2double(get(hObject,'String')) returns contents of
edit4 as a double

% --- Executes during object creation, after setting all


properties.
function edit4_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit4 (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 pushbutton1.


function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)
ips1=handles.ips1;
ips2=handles.ips2;
ips3=handles.ips3;
ipk=(ips1+ips2+ips3)/3;
set(handles.edit4,'String',ipk)

% --- Executes on button press in pushbutton2.


function pushbutton2_Callback(hObject, eventdata, handles)
close
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)
4. Membuat Program GUI hitung fungsi Gelombang berjalan
a. Buat komponen GUI dan masukkan fungsinya
b. Agar tombol buat grafik dapat berfungsi, klik buat grafik lalu pilih view
callback lalu klik callback dan akan muncul ke script

Muncul ke script dan tambahkan fungsi persamaan di file script pada baris
81
c. Pilih Run. Lalu masukkan Nilai A=10, t=5, dan T=4

Hasil scriptnya:
function varargout = GELOMBANGBERJALAN(varargin)
% GELOMBANGBERJALAN MATLAB code for GELOMBANGBERJALAN.fig
% GELOMBANGBERJALAN, by itself, creates a new
GELOMBANGBERJALAN or raises the existing
% singleton*.
%
% H = GELOMBANGBERJALAN returns the handle to a new
GELOMBANGBERJALAN or the handle to
% the existing singleton*.
%
%
GELOMBANGBERJALAN('CALLBACK',hObject,eventData,handles,...)
calls the local
% function named CALLBACK in GELOMBANGBERJALAN.M with the
given input arguments.
%
% GELOMBANGBERJALAN('Property','Value',...) creates a new
GELOMBANGBERJALAN or raises the
% existing singleton*. Starting from the left, property
value pairs are
% applied to the GUI before GELOMBANGBERJALAN_OpeningFcn
gets called. An
% unrecognized property name or invalid value makes
property application
% stop. All inputs are passed to
GELOMBANGBERJALAN_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


GELOMBANGBERJALAN

% Last Modified by GUIDE v2.5 08-Nov-2010 02:29:26

% Begin initialization code - DO NOT EDIT


gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn',
@GELOMBANGBERJALAN_OpeningFcn, ...
'gui_OutputFcn',
@GELOMBANGBERJALAN_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
% End initialization code - DO NOT EDIT

% --- Executes just before GELOMBANGBERJALAN is made visible.


function GELOMBANGBERJALAN_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 GELOMBANGBERJALAN (see
VARARGIN)

% Choose default command line output for GELOMBANGBERJALAN


handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

% UIWAIT makes GELOMBANGBERJALAN wait for user response (see


UIRESUME)
% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command


line.
function varargout = GELOMBANGBERJALAN_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;

% --- Executes on button press in pushbutton1.


function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)
A=handles.A;
t=handles.t;
T=handles.T;
y=A*sin(2*pi*t/T);
set(handles.edit4,'string',y);

% --- Executes on button press in pushbutton2.


function pushbutton2_Callback(hObject, eventdata, handles)
close
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)

function edit1_Callback(hObject, eventdata, handles)


% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)
A=str2num(get(handles.edit1,'string'));
handles.A=A;
guidata(hObject,handles)

% Hints: get(hObject,'String') returns contents of edit1 as


text
% str2double(get(hObject,'String')) returns contents of
edit1 as a double

% --- Executes during object creation, after setting all


properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (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

function edit2_Callback(hObject, eventdata, handles)


% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)
t=str2num(get(handles.edit2,'string'));
handles.t=t;
guidata(hObject,handles)

% Hints: get(hObject,'String') returns contents of edit2 as


text
% str2double(get(hObject,'String')) returns contents of
edit2 as a double

% --- Executes during object creation, after setting all


properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (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

function edit3_Callback(hObject, eventdata, handles)


% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)
T=str2num(get(handles.edit3,'string'));
handles.T=T;
guidata(hObject,handles)

% Hints: get(hObject,'String') returns contents of edit3 as


text
% str2double(get(hObject,'String')) returns contents of
edit3 as a double
% --- Executes during object creation, after setting all
properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (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

function edit4_Callback(hObject, eventdata, handles)


% hObject handle to edit4 (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 edit4 as


text
% str2double(get(hObject,'String')) returns contents of
edit4 as a double

% --- Executes during object creation, after setting all


properties.
function edit4_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit4 (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

5. Membuat Program GUI grafik ezplot dalam bentuk lain


a. Buat komponen GUI dan masukkan fungsinya
b. Agar tombol buat grafik dapat berfungsi, klik buat grafik lalu pilih view
callback lalu klik callback dan akan muncul ke script

Muncul ke script dan tambahkan fungsi persamaan di file script pada baris
81
c. Pilih Run. Lalu masukkan persamaan tan(x) kemudian klik Buat grafik untuk
menampilkan hasil eksekusinya

Hasil Script:
function varargout = NewEzplot(varargin)
% NEWEZPLOT M-file for NewEzplot.fig
% NEWEZPLOT, by itself, creates a new NEWEZPLOT or raises
the existing
% singleton*.
%
% H = NEWEZPLOT returns the handle to a new NEWEZPLOT or
the handle to
% the existing singleton*.
%
% NEWEZPLOT('CALLBACK',hObject,eventData,handles,...)
calls the local
% function named CALLBACK in NEWEZPLOT.M with the given
input arguments.
%
% NEWEZPLOT('Property','Value',...) creates a new
NEWEZPLOT or raises the
% existing singleton*. Starting from the left, property
value pairs are
% applied to the GUI before NewEzplot_OpeningFcn gets
called. An
% unrecognized property name or invalid value makes
property application
% stop. All inputs are passed to NewEzplot_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 NewEzplot

% Last Modified by GUIDE v2.5 08-Nov-2010 01:00:12

% Begin initialization code - DO NOT EDIT


gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @NewEzplot_OpeningFcn,
...
'gui_OutputFcn', @NewEzplot_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
% End initialization code - DO NOT EDIT

% --- Executes just before NewEzplot is made visible.


function NewEzplot_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 NewEzplot (see
VARARGIN)

% Choose default command line output for NewEzplot


handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

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


% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command


line.
function varargout = NewEzplot_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;

% --- Executes on button press in eksekusi.


function eksekusi_Callback(hObject, eventdata, handles)
% hObject handle to eksekusi (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)
fungsi = get(handles.persamaanku,'string');

%%%%hubungkan dengan axes1


hax = handles.axes1;
ezplot (hax,fungsi);
xlabel(hax,'sumbu-x')
ylabel(hax,'sumbu-y')

function persamaanku_Callback(hObject, eventdata, handles)


% hObject handle to persamaanku (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 persamaanku


as text
% str2double(get(hObject,'String')) returns contents of
persamaanku as a double

% --- Executes during object creation, after setting all


properties.
function persamaanku_CreateFcn(hObject, eventdata, handles)
% hObject handle to persamaanku (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 Close.


function Close_Callback(hObject, eventdata, handles)
close
% hObject handle to Close (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)

Tugas Latihan di Modul Lat 3.1, 3.2 dan 4.1

1. Kerjakan Latihan tugas lat 3.1, lat 3.2, lat 4.1


A. Latih 3_1: Membuat Grafik dengan fungsi ezplot
a. Buat komponen GUI dan masukkan fungsinya
b. Agar tombol buat grafik dapat berfungsi, klik buat grafik lalu pilih view
callback lalu klik callback dan akan muncul ke script

Muncul ke script dan tambahkan fungsi persamaan di file script pada


baris 82

c. Pilih Run. Lalu masukkan persamaan 2*sin(x)*cos(x)


Hasil scriptnya:
function varargout = Latih3_1_ezplot(varargin)
% LATIH3_1_EZPLOT M-file for Latih3_1_ezplot.fig
% LATIH3_1_EZPLOT, by itself, creates a new
LATIH3_1_EZPLOT or raises the existing
% singleton*.
%
% H = LATIH3_1_EZPLOT returns the handle to a new
LATIH3_1_EZPLOT or the handle to
% the existing singleton*.
%
%
LATIH3_1_EZPLOT('CALLBACK',hObject,eventData,handles,...)
calls the local
% function named CALLBACK in LATIH3_1_EZPLOT.M with the
given input arguments.
%
% LATIH3_1_EZPLOT('Property','Value',...) creates a new
LATIH3_1_EZPLOT or raises the
% existing singleton*. Starting from the left,
property value pairs are
% applied to the GUI before Latih3_1_ezplot_OpeningFcn
gets called. An
% unrecognized property name or invalid value makes
property application
% stop. All inputs are passed to
Latih3_1_ezplot_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


Latih3_1_ezplot

% Last Modified by GUIDE v2.5 08-Nov-2010 00:32:11

% Begin initialization code - DO NOT EDIT


gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn',
@Latih3_1_ezplot_OpeningFcn, ...
'gui_OutputFcn',
@Latih3_1_ezplot_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
% End initialization code - DO NOT EDIT

% --- Executes just before Latih3_1_ezplot is made visible.


function Latih3_1_ezplot_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 Latih3_1_ezplot (see
VARARGIN)

% Choose default command line output for Latih3_1_ezplot


handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

% UIWAIT makes Latih3_1_ezplot wait for user response (see


UIRESUME)
% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command


line.
function varargout = Latih3_1_ezplot_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;

% --- Executes on button press in eksekusi.


function eksekusi_Callback(hObject, eventdata, handles)
% hObject handle to eksekusi (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)

fungsi = get(handles.persamaanku,'string');

%%%%hubungkan dengan axes1


hax = handles.axes1;
ezplot (hax,fungsi);
xlabel(hax,'sumbu-x')
ylabel(hax,'sumbu-y')

function persamaanku_Callback(hObject, eventdata, handles)


% hObject handle to persamaanku (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


persamaanku as text
% str2double(get(hObject,'String')) returns contents
of persamaanku as a double

% --- Executes during object creation, after setting all


properties.
function persamaanku_CreateFcn(hObject, eventdata, handles)
% hObject handle to persamaanku (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 Close.


function Close_Callback(hObject, eventdata, handles)
% hObject handle to Close (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)

% --- Executes during object creation, after setting all


properties.
function eksekusi_CreateFcn(hObject, eventdata, handles)
% hObject handle to eksekusi (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles empty - handles not created until after all
CreateFcns called
B. Latih 3_2: membuat grafik dalam interval [xmin,xmax]
a. Buat komponen GUI dan masukkan fungsinya

b. Agar tombol buat grafik dapat berfungsi, klik buat grafik lalu pilih view
callback lalu klik callback dan akan muncul ke script

Muncul ke script dan tambahkan fungsi persamaan di file script pada


baris 82

c. Pilih Run. Lalu masukkan persamaan X3-2x+12 dalam interval [-5,6]


Hasil scirptnya:
function varargout = grafik_interval(varargin)
% GRAFIK_INTERVAL M-file for grafik_interval.fig
% GRAFIK_INTERVAL, by itself, creates a new
GRAFIK_INTERVAL or raises the existing
% singleton*.
%
% H = GRAFIK_INTERVAL returns the handle to a new
GRAFIK_INTERVAL or the handle to
% the existing singleton*.
%
%
GRAFIK_INTERVAL('CALLBACK',hObject,eventData,handles,...)
calls the local
% function named CALLBACK in GRAFIK_INTERVAL.M with the
given input arguments.
%
% GRAFIK_INTERVAL('Property','Value',...) creates a new
GRAFIK_INTERVAL or raises the
% existing singleton*. Starting from the left,
property value pairs are
% applied to the GUI before grafik_interval_OpeningFcn
gets called. An
% unrecognized property name or invalid value makes
property application
% stop. All inputs are passed to
grafik_interval_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


grafik_interval

% Last Modified by GUIDE v2.5 08-Nov-2010 01:28:14

% Begin initialization code - DO NOT EDIT


gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn',
@grafik_interval_OpeningFcn, ...
'gui_OutputFcn',
@grafik_interval_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
% End initialization code - DO NOT EDIT

% --- Executes just before grafik_interval is made visible.


function grafik_interval_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 grafik_interval (see
VARARGIN)

% Choose default command line output for grafik_interval


handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

% UIWAIT makes grafik_interval wait for user response (see


UIRESUME)
% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command


line.
function varargout = grafik_interval_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;

% --- Executes on button press in eksekusi.


function eksekusi_Callback(hObject, eventdata, handles)
% hObject handle to eksekusi (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)

fungsi = get(handles.persamaanku,'string');

%%%batas minimal dan maksimal


bts_min = str2num(get(handles.lim_min,'String'));
bts_max = str2num(get(handles.lim_maks,'String'));

%%%%hubungkan dengan axes1


hax = handles.axes1;
ezplot(hax,fungsi);
xlabel(hax,'sumbu-x')
ylabel(hax,'sumbu-y')
xlim( [bts_min bts_max]);

function persamaanku_Callback(hObject, eventdata, handles)


% hObject handle to persamaanku (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


persamaanku as text
% str2double(get(hObject,'String')) returns contents
of persamaanku as a double

% --- Executes during object creation, after setting all


properties.
function persamaanku_CreateFcn(hObject, eventdata, handles)
% hObject handle to persamaanku (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 Close.


function Close_Callback(hObject, eventdata, handles)
% hObject handle to Close (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)

function lim_min_Callback(hObject, eventdata, handles)


% hObject handle to lim_min (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 lim_min


as text
% str2double(get(hObject,'String')) returns contents
of lim_min as a double

% --- Executes during object creation, after setting all


properties.
function lim_min_CreateFcn(hObject, eventdata, handles)
% hObject handle to lim_min (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

function lim_maks_Callback(hObject, eventdata, handles)


% hObject handle to lim_maks (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 lim_maks


as text
% str2double(get(hObject,'String')) returns contents
of lim_maks as a double

% --- Executes during object creation, after setting all


properties.
function lim_maks_CreateFcn(hObject, eventdata, handles)
% hObject handle to lim_maks (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
C. Latih_4.1: Menghitung konversi besaran suhu
a. Buat komponen GUI dan masukkan fungsinya
b. Agar tombol C>R, C>F, dst dapat berfungsi, klik buat grafik lalu pilih
view callback lalu klik callback dan akan muncul ke script

Muncul ke script dan tambahkan fungsi persamaan di file script pada


baris 104, 113, 122, 131, 140, 147, 156, 165, 174, 183, 192, 201,210

c. Pilih Run. Lalu masukkan nilai suhu 30 lalu klik C>F dan keluar hasilnya
Hasil scriptnya:
function varargout = konversi(varargin)
% KONVERSI M-file for konversi.fig
% KONVERSI, by itself, creates a new KONVERSI or raises
the existing
% singleton*.
%
% H = KONVERSI returns the handle to a new KONVERSI or
the handle to
% the existing singleton*.
%
% KONVERSI('CALLBACK',hObject,eventData,handles,...)
calls the local
% function named CALLBACK in KONVERSI.M with the given
input arguments.
%
% KONVERSI('Property','Value',...) creates a new
KONVERSI or raises the
% existing singleton*. Starting from the left,
property value pairs are
% applied to the GUI before konversi_OpeningFcn gets
called. An
% unrecognized property name or invalid value makes
property application
% stop. All inputs are passed to konversi_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


konversi

% Last Modified by GUIDE v2.5 08-Nov-2010 12:29:17

% Begin initialization code - DO NOT EDIT


gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @konversi_OpeningFcn,
...
'gui_OutputFcn', @konversi_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
% End initialization code - DO NOT EDIT

% --- Executes just before konversi is made visible.


function konversi_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 konversi (see
VARARGIN)

% Choose default command line output for konversi


handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

% UIWAIT makes konversi wait for user response (see


UIRESUME)
% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command


line.
function varargout = konversi_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;

function masukan_Callback(hObject, eventdata, handles)


% hObject handle to masukan (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 masukan
as text
% str2double(get(hObject,'String')) returns contents
of masukan as a double

% --- Executes during object creation, after setting all


properties.
function masukan_CreateFcn(hObject, eventdata, handles)
% hObject handle to masukan (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 celcius_reamur.


function celcius_reamur_Callback(hObject, eventdata,
handles)
% hObject handle to celcius_reamur (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)
data=str2num(get(handles.masukan,'string'));
hasil= 4/5*data;
set(handles.hasilku,'string',num2str(hasil));

% --- Executes on button press in celsius_farhen.


function celsius_farhen_Callback(hObject, eventdata,
handles)
% hObject handle to celsius_farhen (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)
data=str2num(get(handles.masukan,'string'));
hasil= 9/5*data+32;
set(handles.hasilku,'string',num2str(hasil));

% --- Executes on button press in celcius_kelvin.


function celcius_kelvin_Callback(hObject, eventdata,
handles)
% hObject handle to celcius_kelvin (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)
data=str2num(get(handles.masukan,'string'));
hasil= data+273;
set(handles.hasilku,'string',num2str(hasil));

% --- Executes on button press in reamur_celcius.


function reamur_celcius_Callback(hObject, eventdata,
handles)
% hObject handle to reamur_celcius (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)
data=str2num(get(handles.masukan,'string'));
hasil= 5/4*data;
set(handles.hasilku,'string',num2str(hasil));

% --- Executes on button press in tutup.


function tutup_Callback(hObject, eventdata, handles)
% hObject handle to tutup (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)
close

% --- Executes on button press in reamur_farhen.


function reamur_farhen_Callback(hObject, eventdata, handles)
% hObject handle to reamur_farhen (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)
data=str2num(get(handles.masukan,'string'));
hasil= 9/4*data+32;
set(handles.hasilku,'string',num2str(hasil));

% --- Executes on button press in reamur_kelvin.


function reamur_kelvin_Callback(hObject, eventdata, handles)
% hObject handle to reamur_kelvin (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)
data=str2num(get(handles.masukan,'string'));
hasil= 5/4*data+273;
set(handles.hasilku,'string',num2str(hasil));

% --- Executes on button press in farhen_celcius.


function farhen_celcius_Callback(hObject, eventdata,
handles)
% hObject handle to farhen_celcius (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)
data=str2num(get(handles.masukan,'string'));
hasil= 5/9*(data-32);
set(handles.hasilku,'string',num2str(hasil));

% --- Executes on button press in fahren_reamur.


function fahren_reamur_Callback(hObject, eventdata, handles)
% hObject handle to fahren_reamur (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)
data=str2num(get(handles.masukan,'string'));
hasil= 4/9*(data-32);
set(handles.hasilku,'string',num2str(hasil));

% --- Executes on button press in farhen_kelvin.


function farhen_kelvin_Callback(hObject, eventdata, handles)
% hObject handle to farhen_kelvin (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)
data=str2num(get(handles.masukan,'string'));
hasil= 5/9*(data+459.4);
set(handles.hasilku,'string',num2str(hasil));

% --- Executes on button press in kelvin_celcius.


function kelvin_celcius_Callback(hObject, eventdata,
handles)
% hObject handle to kelvin_celcius (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)
data=str2num(get(handles.masukan,'string'));
hasil= data-273;
set(handles.hasilku,'string',num2str(hasil));

% --- Executes on button press in kelvin_reamur.


function kelvin_reamur_Callback(hObject, eventdata, handles)
% hObject handle to kelvin_reamur (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)
data=str2num(get(handles.masukan,'string'));
hasil= 4/5*(data-273);
set(handles.hasilku,'string',num2str(hasil));

% --- Executes on button press in kelvin_farhen.


function kelvin_farhen_Callback(hObject, eventdata, handles)
% hObject handle to kelvin_farhen (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)
data=str2num(get(handles.masukan,'string'));
hasil= 9/5*data-459.4;
set(handles.hasilku,'string',num2str(hasil));

Anda mungkin juga menyukai