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')
0 件のコメント
採用された回答
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 件のコメント
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 Center および File Exchange で Migrate GUIDE Apps についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!