Pengunjung

Kamis, 04 Juli 2013

Membuat GUI untuk Logika Fuzzy

Pada artikel sebelumnya saya sudah menulis judul artikel "Menyelesaikan Logika Fuzzy Mamdani Menggunakan Matlab". Secara lengkap saya telah membahas cara menyelesaikan prediksi banjir menggunakan logika fuzzy dengan bantuan software MATLAB. Pada artikel ini saya akan memberikan sedikit ilmu untuk membuat tampilan GUI logika fuzzy untuk studi kasus prediksi banjir yang saya jelaskan pada tulisan sebelumnya. 

 Untuk membuat GUI pada prediksi banjir menggunakan logika fuzzy. Pertama kita save file prediksi banjir yang telah diselesaikan dengan logika fuzzy dan file GUI untuk menyelesaikannya dalam satu folder. Ketik guide pada commond windows sehingga muncul tampilan sebagai berikut:


Klik ok. Kemudian klik Button Group pada menu disampingnya. kemudian kita edit menjadi input dan output. Sehingga tampilanya seperti gambar dibawah ini:


Selanjutnya kita klik Static Text. kemudian klik 2x sehingga muncul akan muncul tampilan inspector. Setelah itu ganti Static Text pada string dengan variabel inputan dan outputan dalam kasus prediksi banjir . Maka tampilanya sebagai berikut:

 
Selanjutnya kita klik Edit Text. kemudian klik 2x sehingga muncul akan muncul tampilan inspector. Setelah itu hapus semua Edit Text pada string dan ganti tag dengan curah_hujan, lama_hujan, debit_sungai dan prediksi  .Maka tampilanya sebagai berikut:


Selanjutnya kita klik Push button. kemudian klik 2x sehingga muncul akan muncul tampilan inspector. Setelah itu ganti Push button pada string dan tag dengan Running dan Exit  .Maka tampilanya sebagai berikut:


Selanjutnya save dan Running. Terus masukan source code berikut:

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

% Last Modified by GUIDE v2.5 12-Jun-2013 09:49:20

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @bisa_OpeningFcn, ...
                   'gui_OutputFcn',  @bisa_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 bisa is made visible.
function bisa_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 bisa (see VARARGIN)

% Choose default command line output for bisa
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes bisa wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = bisa_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 prediksi_Callback(hObject, eventdata, handles)
% hObject    handle to prediksi (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 prediksi as text
%        str2double(get(hObject,'String')) returns contents of prediksi as a double


% --- Executes during object creation, after setting all properties.
function prediksi_CreateFcn(hObject, eventdata, handles)
% hObject    handle to prediksi (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 curah_hujan_Callback(hObject, eventdata, handles)
% hObject    handle to curah_hujan (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 curah_hujan as text
%        str2double(get(hObject,'String')) returns contents of curah_hujan as a double
curah_hujan=str2double(get(hObject,'string'));
handles.curah_hujan=curah_hujan;
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function curah_hujan_CreateFcn(hObject, eventdata, handles)
% hObject    handle to curah_hujan (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 lama_hujan_Callback(hObject, eventdata, handles)
% hObject    handle to lama_hujan (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 lama_hujan as text
%        str2double(get(hObject,'String')) returns contents of lama_hujan as a double

lama_hujan=str2double(get(hObject,'string'));
handles.lama_hujan=lama_hujan;
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function lama_hujan_CreateFcn(hObject, eventdata, handles)
% hObject    handle to lama_hujan (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 debit_sungai_Callback(hObject, eventdata, handles)
% hObject    handle to debit_sungai (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 debit_sungai as text
%        str2double(get(hObject,'String')) returns contents of debit_sungai as a double

debit_sungai=str2double(get(hObject,'string'));
handles.debit_sungai=debit_sungai;
guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.
function debit_sungai_CreateFcn(hObject, eventdata, handles)
% hObject    handle to debit_sungai (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 Running.
function Running_Callback(hObject, eventdata, handles)
% hObject    handle to Running (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
a=readfis('fuzzy_banjir')
out=evalfis([handles. curah_hujan handles. lama_hujan handles. debit_sungai], a)
set(handles. prediksi, 'string', out);


% --- Executes on button press in Exit.
function Exit_Callback(hObject, eventdata, handles)
% hObject    handle to Exit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
close

Maka Tampilan akhirnya sebagai berikut:


2 komentar:

Agus Salim mengatakan...

gmana cara buat source codex gan?

Rio mengatakan...

java gui dengan logika fuzy ga ada pak?

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Lady Gaga, Salman Khan