Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Function: Varargout Matlabhafizh2 (Varargin)

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

function varargout = matlabhafizh2(varargin)

% MATLABHAFIZH2 MATLAB code for matlabhafizh2.fig


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


matlabhafizh2

% Last Modified by GUIDE v2.5 05-May-2019 05:50:21

% Begin initialization code - DO NOT EDIT


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


function matlabhafizh2_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 matlabhafizh2 (see
VARARGIN)

% Choose default command line output for matlabhafizh2


handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

% UIWAIT makes matlabhafizh2 wait for user response (see


UIRESUME)
% uiwait(handles.figure1);

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


command line.
function varargout = matlabhafizh2_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)
g=9.8;
kecepatan=str2double(get(handles.edit1,'string'));
pilih=handles.pilih;
switch handles.pilih
case 1
vx=kecepatan*cos((15)*pi()./180);
tmaks=vx./g;
ts=2*tmaks;

hmaks=((kecepatan^2)*(sin((15)*pi()./180)).^2)./(2*g);
vy=kecepatan*sin((15)*pi()./180);
s=vy*ts;
case 2
vx=kecepatan*cos((30)*pi()./180);
tmaks=vx./g;
ts=2*tmaks;

hmaks=((kecepatan^2)*(sin((30)*pi()./180)).^2)./(2*g);
vy=kecepatan*sin((30)*pi()./180);
s=vy*ts;
case 3
vx=kecepatan*cos((45)*pi()./180);
tmaks=vx./g;
ts=2*tmaks;
hmaks=((kecepatan^2)*(sin((45)*pi()./180)).^2)./(2*g);
vy=kecepatan*sin((45)*pi()./180);
s=vy*ts;
case 4
vx=kecepatan*cos((60)*pi()./180);
tmaks=vx./g;
ts=2*tmaks;

hmaks=((kecepatan^2)*(sin((60)*pi()./180)).^2)./(2*g);
vy=kecepatan*sin((60)*pi()./180);
s=vy*ts;
end
set(handles.edit2,'string',hmaks);
set(handles.edit3,'string',s);
set(handles.edit4,'string',ts);

% --- 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)
g=9.8;
kecepatan=str2double(get(handles.edit1,'string'));
pilih=handles.pilih;
switch handles.pilih
case 1
vx=kecepatan*cos((15)*pi()./180);
tmaks=vx./g;
ts=2*tmaks;

hmaks=((kecepatan^2)*(sin((15)*pi()./180)).^2)./(2*g);
vy=kecepatan*sin((15)*pi()./180);
s=vy*ts;
tx=0:0.01:ts;
h=vx*tx-0.5*g*tx.^2;
axes(handles.axes1);
plot(tx,h);
case 2
vx=kecepatan*cos((30)*pi()./180);
tmaks=vx./g;
ts=2*tmaks;
hmaks=((kecepatan^2)*(sin((30)*pi()./180)).^2)./(2*g);
vy=kecepatan*sin((30)*pi()./180);
s=vy*ts;
tx=0:0.01:ts;
h=vx*tx-0.5*g*tx.^2;
axes(handles.axes1);
plot(tx,h);
case 3
vx=kecepatan*cos((45)*pi()./180);
tmaks=vx./g;
ts=2*tmaks;

hmaks=((kecepatan^2)*(sin((45)*pi()./180)).^2)./(2*g);
vy=kecepatan*sin((45)*pi()./180);
s=vy*ts;
tx=0:0.01:ts;
h=vx*tx-0.5*g*tx.^2;
axes(handles.axes1);
plot(tx,h);
case 4
vx=kecepatan*cos((60)*pi()./180);
tmaks=vx./g;
ts=2*tmaks;

hmaks=((kecepatan^2)*(sin((60)*pi()./180)).^2)./(2*g);
vy=kecepatan*sin((60)*pi()./180);
s=vy*ts;
tx=0:0.01:ts;
h=vx*tx-0.5*g*tx.^2;
axes(handles.axes1);
plot(tx,h);
end
xlabel('waktu(s)');ylabel('tinggi(m)');
legend('Simulasi Peluru Oleh Hafizh');
grid on
set(handles.edit2,'string',hmaks);
set(handles.edit3,'string',s);
set(handles.edit4,'string',ts);

% --- Executes on button press in pushbutton3.


function pushbutton3_Callback(hObject, eventdata, handles)
% 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)
set(handles.edit1,'string',0);
set(handles.edit2,'string',0);
set(handles.edit3,'string',0);
set(handles.edit4,'string',0);
set(handles.checkbox1,'string',0);
set(handles.radiobutton1,'string',0);
set(handles.radiobutton2,'string',0);
set(handles.radiobutton3,'string',0);
set(handles.radiobutton4,'string',0);
axes(handles.axes1);
plot(0,0);

% --- Executes on button press in pushbutton4.


function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (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)

% 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

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 button press in checkbox1.


function checkbox1_Callback(hObject, eventdata, handles)
% hObject handle to checkbox1 (see GCBO)
% eventdata reserved - to be defined in a future version
of MATLAB
% handles structure with handles and user data (see
GUIDATA)
nilai=get(handles.checkbox1,'value');
if nilai==1
grid on;
else
grid off;
end
% Hint: get(hObject,'Value') returns toggle state of
checkbox1

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

% --- 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)
set(handles.radiobutton1,'value',0);
set(handles.radiobutton2,'value',0);
set(handles.radiobutton4,'value',0);
pilih=3;
handles.pilih=pilih;
guidata(hObject,handles);
% Hint: get(hObject,'Value') returns toggle state of
radiobutton3
% --- 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)
set(handles.radiobutton1,'value',0);
set(handles.radiobutton2,'value',0);
set(handles.radiobutton3,'value',0);
pilih=4;
handles.pilih=pilih;
guidata(hObject,handles);
% Hint: get(hObject,'Value') returns toggle state of
radiobutton4

You might also like