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

4 vues (au cours des 30 derniers jours)
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')

Réponse acceptée

Geoff Hayes
Geoff Hayes le 26 Avr 2015
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 commentaires
Yeap Jia Wei
Yeap Jia Wei le 29 Avr 2015
Modifié(e) : Yeap Jia Wei le 29 Avr 2015
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 le 29 Avr 2015
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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur View and Analyze Simulation Results dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by