0% found this document useful (0 votes)
36 views

Varargout Tugas - GUI (Varargin) : Function

The document describes the code for a GUI created in MATLAB. It contains functions that initialize the GUI, handle callbacks from different controls like sliders and edits, and perform fuzzy logic calculations to determine the temperature setting for an air conditioner based on user inputs for room size, number of people, and outdoor temperature.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

Varargout Tugas - GUI (Varargin) : Function

The document describes the code for a GUI created in MATLAB. It contains functions that initialize the GUI, handle callbacks from different controls like sliders and edits, and perform fuzzy logic calculations to determine the temperature setting for an air conditioner based on user inputs for room size, number of people, and outdoor temperature.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

function varargout = Tugas_GUI(varargin)

% GUIDETEMPLATE0 MATLAB code for guidetemplate0.fig


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

% Copyright 2002-2006 The MathWorks, Inc.


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

% Last Modified by GUIDE v2.5 21-Oct-2021 09:35:51

% Begin initialization code - DO NOT EDIT


gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @guidetemplate0_OpeningFcn, ...
'gui_OutputFcn', @guidetemplate0_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 guidetemplate0 is made visible.


function guidetemplate0_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 guidetemplate0 (see VARARGIN)

% Choose default command line output for guidetemplate0


handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

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


% uiwait(handles.figure1);

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


function LuasRuangan_Callback(hObject, eventdata, handles)
% hObject handle to LuasRuangan (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,'Value') returns position of slider


% get(hObject,'Min') and get(hObject,'Max') to determine range of
slider

LuasRuangan = get(hObject,'Value');
set(handles.edit1, 'string', strcat(num2str(LuasRuangan),' M^2'));
if LuasRuangan <= 15
LR = 'sempit';
elseif LuasRuangan > 15 && LuasRuangan <= 35
LR = 'sedang';
else
LR = 'Luas';
end
set(handles.textLR, 'string', LR);

JumlahOrang = get(handles.JumlahOrang,'Value');
SuhuLuarRuangan = get(handles.SuhuLuarRuangan,'Value');
input = [LuasRuangan JumlahOrang SuhuLuarRuangan];
fis = readfis('Tugas Jobsheet 3');
out = evalfis(input,fis);
if out <= 15
Suhu_AC = 'Turunkan';
elseif out > 15 && out <= 35
Suhu_AC = 'stabilkan';
else
Suhu_AC = 'Naikan';
end
set(handles.edit4,'string',strcat(num2str(out),' C'));
set(handles.Suhu_AC, 'string', Suhu_AC);

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


function LuasRuangan_CreateFcn(hObject, eventdata, handles)
% hObject handle to LuasRuangan (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.


if isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end

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

% --- Executes on slider movement.


function JumlahOrang_Callback(hObject, eventdata, handles)
% hObject handle to JumlahOrang (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,'Value') returns position of slider


% get(hObject,'Min') and get(hObject,'Max') to determine range of
slider

JumlahOrang = get(hObject,'Value');
set(handles.edit2, 'string', strcat(num2str(JumlahOrang),' '));
if JumlahOrang <= 12
Jo = 'Sedikit';
elseif JumlahOrang > 12 && JumlahOrang <= 22
Jo = 'Cukup';
else
Jo = 'Banyak';
end
set(handles.textJO, 'string', Jo);

LuasRuangan = get(handles.LuasRuangan,'Value');
SuhuLuarRuangan = get(handles.SuhuLuarRuangan,'Value');
input = [LuasRuangan JumlahOrang SuhuLuarRuangan];
fis = readfis('Tugas Jobsheet 3');
out = evalfis(input,fis);
if out <= 15
Suhu_AC = 'Turunkan';
elseif out > 15 && out <= 35
Suhu_AC = 'stabilkan';
else
Suhu_AC = 'Naikan';
end
set(handles.edit4,'string',strcat(num2str(out),' C'));
set(handles.Suhu_AC, 'string', Suhu_AC);
% --- Executes during object creation, after setting all properties.
function JumlahOrang_CreateFcn(hObject, eventdata, handles)
% hObject handle to JumlahOrang (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.


if isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end

% --- Executes on slider movement.


function SuhuLuarRuangan_Callback(hObject, eventdata, handles)
% hObject handle to SuhuLuarRuangan (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,'Value') returns position of slider


% get(hObject,'Min') and get(hObject,'Max') to determine range of
slider

SuhuLuarRuangan = get(hObject,'Value');
set(handles.edit3, 'string', strcat(num2str(SuhuLuarRuangan),' C'));
if SuhuLuarRuangan <= 18
SLR = 'Hujan';
elseif SuhuLuarRuangan > 18 && SuhuLuarRuangan <= 32
SLR = 'Berawan';
else
SLR = 'Cerah';
end
set(handles.textSLR, 'string', SLR);

JumlahOrang = get(handles.JumlahOrang,'Value');
LuasRuangan = get(handles.LuasRuangan,'Value');
input = [LuasRuangan JumlahOrang SuhuLuarRuangan];
fis = readfis('Tugas Jobsheet 3');
out = evalfis(input,fis);
if out <= 15
Suhu_AC = 'Turunkan';
elseif out > 15 && out <= 35
Suhu_AC = 'stabilkan';
else
Suhu_AC = 'Naikan';
end
set(handles.edit4,'string',strcat(num2str(out),' C'));
set(handles.Suhu_AC, 'string', Suhu_AC);

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


function SuhuLuarRuangan_CreateFcn(hObject, eventdata, handles)
% hObject handle to SuhuLuarRuangan (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.


if isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
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)
% 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

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

You might also like