Sie sind auf Seite 1von 14

TUGAS 2

PIRANTI LUNAK TELEKOMUNIKASI LANJUT


GUIDE (GUI Builder) MATLAB

Oleh :
I Gusti Ngurah Agung Dwi Jaya Putra (1304405054)

Jurusan Teknik Elektro dan Komputer


Fakultas Teknik
Universitas Udayana
2016

TUGAS 2.1
MENGHITUNG LUAS & KELILING LINGKARAN

Gambar 1 Hasil Perhitungan Lingkaran dengan jari-jari 10

Gambar 2 Hasil Perhitungan Lingkaran dengan jari-jari 4

Source Code
function varargout = lingkaran(varargin)
% LINGKARAN MATLAB code for lingkaran.fig
%
LINGKARAN, by itself, creates a new LINGKARAN or raises the existing
%
singleton*.
%
%
H = LINGKARAN returns the handle to a new LINGKARAN or the handle to
%
the existing singleton*.
%
%
LINGKARAN('CALLBACK',hObject,eventData,handles,...) calls the local
%
function named CALLBACK in LINGKARAN.M with the given input
arguments.
%
%
LINGKARAN('Property','Value',...) creates a new LINGKARAN or raises
the
%
existing singleton*. Starting from the left, property value pairs
are
%
applied to the GUI before lingkaran_OpeningFcn gets called. An
%
unrecognized property name or invalid value makes property
application
%
stop. All inputs are passed to lingkaran_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 lingkaran
% Last Modified by GUIDE v2.5 13-Oct-2016 23:21:16
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',
mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @lingkaran_OpeningFcn, ...
'gui_OutputFcn', @lingkaran_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 lingkaran is made visible.


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

%
%
%
%
%

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 lingkaran (see VARARGIN)

% Choose default command line output for lingkaran


handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes lingkaran wait for user response (see UIRESUME)
% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = lingkaran_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)

% --- 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)
% Hint: get(hObject,'Value') returns toggle state of radiobutton1

% --- Executes on button press in radiobutton4.


function radiobutton4_Callback(hObject, eventdata, handles)
% hObject
handle to radiobutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles
structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of radiobutton4

% --- Executes on button press in radiobutton5.


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

% --- Executes on button press in radiobutton5.


function radiobutton5_Callback(hObject, eventdata, handles)
% hObject
handle to radiobutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles
structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of radiobutton5

% --- Executes on button press in radiobutton6.


function radiobutton6_Callback(hObject, eventdata, handles)
% hObject
handle to radiobutton6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles
structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of radiobutton6

function edit1_Callback(hObject, eventdata, handles)


jari=str2num(get(handles.edit1, 'String'));
handles.jari=jari;
guidata(hObject, 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 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)
% 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)

% 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)
% 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

% --- Executes on button press in btn_hitung.


function btn_hitung_Callback(hObject, eventdata, handles)
%kode ini dieksekusi jika kita menekan tombol hitung
jari=handles.jari;
luas=pi*jari*jari;
kel=2*pi*jari;
%menampilkan hasil perhitungan
set(handles.edit2, 'string', luas);
set(handles.edit3, 'string', kel);
% hObject
handle to btn_hitung (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles
structure with handles and user data (see GUIDATA)

set(handles.edit2, 'string', luas);


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

% --- Executes on button press in btn_exit.


function btn_exit_Callback(hObject, eventdata, handles)
%untuk keluar dari aplikasi
delete(handles.figure1)
% hObject
handle to btn_exit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles
structure with handles and user data (see GUIDATA)

TUGAS 2.2
TRIGONOMETRI

Gambar x.x Hasil Perhitungan Trigonometri dengan Sinus

Gambar x.x Hasil Perhitungan Trigonometri dengan Cosinus

Source Code
function varargout = trigonometri(varargin)
% TRIGONOMETRI MATLAB code for trigonometri.fig
%
TRIGONOMETRI, by itself, creates a new TRIGONOMETRI or raises the
existing
%
singleton*.
%
%
H = TRIGONOMETRI returns the handle to a new TRIGONOMETRI or the
handle to
%
the existing singleton*.
%
%
TRIGONOMETRI('CALLBACK',hObject,eventData,handles,...) calls the
local
%
function named CALLBACK in TRIGONOMETRI.M with the given input
arguments.
%
%
TRIGONOMETRI('Property','Value',...) creates a new TRIGONOMETRI or
raises the
%
existing singleton*. Starting from the left, property value pairs
are
%
applied to the GUI before trigonometri_OpeningFcn gets called. An
%
unrecognized property name or invalid value makes property
application
%
stop. All inputs are passed to trigonometri_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 trigonometri
% Last Modified by GUIDE v2.5 14-Oct-2016 00:08:07
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',
mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @trigonometri_OpeningFcn, ...
'gui_OutputFcn', @trigonometri_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 trigonometri is made visible.


function trigonometri_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 trigonometri (see VARARGIN)
% Choose default command line output for trigonometri
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes trigonometri wait for user response (see UIRESUME)
% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = trigonometri_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)
indeks=get(handles.popupmenu2, 'Value');
%mengambil nilai
if indeks==1
%jika menekan pilihan
T=1;
%maka T=1;
else if indeks==2
%jika menekan pilihan
T=2;
%maka T=2;
else if indeks==3
%jika menekan pilihan
T=3;
%maka T=3;
else if indeks==4
%jika menekan pilihan
T=4;
%maka T=4;
end
end
end
end

1
2
3
4

A=str2num(get(handles.edit1, 'string'));
r=str2num(get(handles.edit2, 'string'));
x=-10:0.1:10;

%mengambil nilai pada edit1


%mengambil nilai pada edit2
%membangkitkan sumbu x

pilih=handles.pilih
radio button
switch handles.pilih
case 1
y=A*sin(T*x+r);
case 2
y=A*cos(T*x+r);
end

%berhubungan dengan pilihan pada

axes(handles.axes1);
a=0;
dan sumbu y

%jika
%maka
%jika
%maka

radiobutton1 yang ditekan


menghitung nilai sinus
radiobutton2 yang ditekan
menghitung nilai cosinus

%membuat garis, seperti sumbu x

axes(handles.axes1);
a=0;
%membuat garis, seperti sumbu x
dan sumbu y
plot(x,y,'r', a,x,'b', x,a,'b');
grid on
% 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)

% --- Executes on button press in pushbutton2.


function pushbutton2_Callback(hObject, eventdata, handles)
set(handles.edit1, 'string', ''); %mengosongkan string pada edit1
set(handles.edit2, 'string', ''); %mengosongkan string pada edit2
axes(handles.axes1);
plot(0);
% 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)
% 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)
% 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)

% --- 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

% --- Executes on selection change in popupmenu.


function popupmenu_Callback(hObject, eventdata, handles)
indeks=get(handles.popupmenu,'Value');
handles.indeks=indeks;
guidata(hObject,handles);
% hObject
handle to popupmenu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles
structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu
contents as cell array
%
contents{get(hObject,'Value')} returns selected item from popupmenu

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


function popupmenu_CreateFcn(hObject, eventdata, handles)
% hObject
handle to popupmenu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles
empty - handles not created until after all CreateFcns called
% Hint: popupmenu 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 radiobutton3.


function radiobutton3_Callback(hObject, eventdata, handles)
% hObject
handle to radiobutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles
structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of radiobutton3

% --- Executes on button press in radiobutton1.


function radiobutton1_Callback(hObject, eventdata, handles)
set(handles.radiobutton2,'Value',0);
pilih=1;
handles.pilih=pilih;
guidata(hObject,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)

% --- Executes on button press in radiobutton1.


function radiobutton1_Callback(hObject, eventdata, handles)
set(handles.radiobutton2,'Value',0);
pilih=1;
handles.pilih=pilih;
guidata(hObject,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)
% Hint: get(hObject,'Value') returns toggle state of radiobutton1

% --- Executes on button press in radiobutton2.


function radiobutton2_Callback(hObject, eventdata, handles)
set(handles.radiobutton1,'Valve',0);
pilih=2;
handles.pilih=pilih;
guidata(hObject,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)
% Hint: get(hObject,'Value') returns toggle state of radiobutton2

% --- Executes on selection change in popupmenu2.


function popupmenu2_Callback(hObject, eventdata, handles)
% hObject
handle to popupmenu2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles
structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu2
contents as cell array
%
contents{get(hObject,'Value')} returns selected item from
popupmenu2

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


function popupmenu2_CreateFcn(hObject, eventdata, handles)
% hObject
handle to popupmenu2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles
empty - handles not created until after all CreateFcns called
% Hint: popupmenu 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 pushbutton3.


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

% --- Executes on button press in pushbutton3.


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

Das könnte Ihnen auch gefallen