필터 지우기
필터 지우기

How do i create GUI using projectile motion? The GUI is required to be able to input value of x0,y0,v0x,v0y and also able able user to press'redraw plot' button to update figure for projectile motion

조회 수: 2 (최근 30일)
x0=0;
y0=10;
v0=5;
angle0=(pi/3);
v0x= v0*cos(pi*(angle0/180));
v0y= v0*sin(pi*(angle0/180));
g=9.81;
time = calc_time(g,v0y,y0)
range= calc_range(v0x,time)
v_final=calc_v_final(v0x,v0y)
t=linspace(0,time,100);
x=x0+ v0*cos(angle0)*t;
y=y0+ v0*sin(angle0)*t - g*t.^2/2;
plot(x,y)
xlabel('x-direction displacement');
ylabel('y-direction displacement');
title ('Projectile Motion')

채택된 답변

Geoff Hayes
Geoff Hayes 2015년 4월 26일
Yeap Jia Wei - try using GUIDE to create a GUI that will have four edit text fields (for the x0, y0, v0x, and v0y inputs), a push button for the (re)draw function, and an axes to plot the data. Your above code will need to be converted into a function so that the push button callback will be able to call it and pass the four inputs to it. For example, the function could be
function [x,y] = calcProjectileMotion(x0,y0,v0x,v0y)
g=9.81;
time = calc_time(g,v0y,y0)
range= calc_range(v0x,time)
v_final=calc_v_final(v0x,v0y)
t=linspace(0,time,100);
x=x0+ v0x*t;
y=y0+ v0y*t - g*t.^2/2;
Note how the above returns the projectile motion in the x and y directions which your GUI code (in the push button callback) will plot within the axes.
  댓글 수: 2
Yeap Jia Wei
Yeap Jia Wei 2015년 4월 29일
편집: Yeap Jia Wei 2015년 4월 29일
I have input these conversion to the respective command, what should i do next? Should i link this 4 values to my push button,'Redraw plot'? How? using createFcn?
function edit8_Callback(hObject, eventdata, handles)
% hObject handle to edit8 (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 edit8 as text
% str2double(get(hObject,'String')) returns contents of edit8 as a double
x0 = str2num(char(get(handles.edit8,'String')));
Geoff Hayes
Geoff Hayes 2015년 4월 29일
Use the pushbutton callback to get the four values from the edit fields and then call your function whose return values you will try to plot.
function pushbutton1_Callback(hObject, eventdata, handles)
x0 = str2num(char(get(handles.edit8,'String')));
y0 = ...;
v0x = ...;
v0y = ...;
[x,y] = calcProjectileMotion(x0,y0,v0x,v0y)
% now plot the data in your axes

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 View and Analyze Simulation Results에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by