Tuesday, March 28, 2017

Cara Mudah Membuat Konversi Panjang Menggunakan MATLAB (GUI)

Cara Mudah Membuat Konversi Panjang Menggunakan MATLAB (GUI)

Untuk temen-temen yang kesulitan untuk membuat program KONVERSI PANJANG menggunakan MATLAB (GUI) jangan bingung apalagi panik..
Berikut ini adalah program yang telah saya buat



1. Buka Program MATLAB di PC/Laptop, lalu masuk ke menu File-New-Script



2. Copas script dibawah ini

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

% Last Modified by GUIDE v2.5 17-Dec-2016 09:25:24

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

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

% Update handles structure
guidata(hObject, handles);

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


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


% --- Executes during object creation, after setting all properties.
function m_CreateFcn(hObject, eventdata, handles)
% hObject    handle to m (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 hitungkm.
function hitungkm_Callback(hObject, eventdata, handles)
% hObject    handle to hitungkm (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
proyek=guidata(gcbo);
meter=str2double(get(proyek.m,'String'));
kilometer=meter/1000
set(proyek.km,'String',num2str(kilometer));


% --- Executes on button press in hitunghm.
function hitunghm_Callback(hObject, eventdata, handles)
% hObject    handle to hitunghm (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
proyek=guidata(gcbo);
meter=str2double(get(proyek.m,'String'));
hm=meter/100
set(proyek.hm,'String',num2str(hm));


% --- Executes on button press in hitungdam.
function hitungdam_Callback(hObject, eventdata, handles)
% hObject    handle to hitungdam (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
proyek=guidata(gcbo);
meter=str2double(get(proyek.m,'String'));
dam=meter/10
set(proyek.dam,'String',num2str(dam));


% --- Executes on button press in hitungcm.
function hitungcm_Callback(hObject, eventdata, handles)
% hObject    handle to hitungcm (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
proyek=guidata(gcbo);
meter=str2double(get(proyek.m,'String'));
cm=meter*100
set(proyek.cm,'String',num2str(cm));


% --- Executes on button press in hitungdm.
function hitungdm_Callback(hObject, eventdata, handles)
% hObject    handle to hitungdm (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
proyek=guidata(gcbo);
meter=str2double(get(proyek.m,'String'));
dm=meter*10
set(proyek.dm,'String',num2str(dm));


% --- Executes on button press in hitungmm.
function hitungmm_Callback(hObject, eventdata, handles)
% hObject    handle to hitungmm (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
proyek=guidata(gcbo);
meter=str2double(get(proyek.m,'String'));
mm=meter*1000
set(proyek.mm,'String',num2str(mm));



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


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


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


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


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


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


% --- Executes during object creation, after setting all properties.
function mm_CreateFcn(hObject, eventdata, handles)
% hObject    handle to mm (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 keluar.
function keluar_Callback(hObject, eventdata, handles)
% hObject    handle to keluar (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 reset.
function reset_Callback(hObject, eventdata, handles)
% hObject    handle to reset (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
proyek=guidata(gcbo);
set(proyek.m,'String',' ');
set(proyek.km,'String',' ');
set(proyek.hm,'String',' ');
set(proyek.dam,'String',' ');
set(proyek.dm,'String',' ');
set(proyek.cm,'String',' ');
set(proyek.mm,'String',' ');

3. Setelah itu run Program tersebut
4. Finish

Sekian tutorial singkatnya dari saya
Untuk lebih detailnya bisa download filenya disini
DOWNLOAD DISINI
DOWNLOAD DISINI
DOWNLOAD DISINI

No comments:

Post a Comment