MATLAB: 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

guimotionprojectileprojectilemotion

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')

Best Answer

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.