フィルターのクリア

How to display values from a chart into the command window

7 ビュー (過去 30 日間)
Stephen Mixon
Stephen Mixon 2019 年 10 月 28 日
編集済み: Daniel M 2019 年 10 月 28 日
I am modeling a 3d projectile. I was wondering how to get the end coordinates of the plot to appear in the command window so I dont have to manually find them. Here is the code. I want the values of x,y,z.
figure('name','Projectile Motion')
xlabel('X (m)')
ylabel('Y (m)')
zlabel('Z (m)')
% This sets the viewing angle
view([1 -1 1])
% This sets the limits on the x- and y-axes
xlim([0,3000])
ylim([0,3000])
zlim([0,1000])
box('on')
grid('on')
hold on
% az is azimuth angle, el is elevation
V0 = 150;
az = 45;
el= 30;
t = [0:0.01:25]';
v = sqrt(vx0^2+vy0^2+vz0^2)
vx0 = V0*cosd(az)*cosd(el);
vy0 = V0*sind(az)*cosd(el);
vz0 = V0*sind(el);
x = vx0.*t;
y = vy0.*t;
z = vz0*t-0.5*9.81.*t.^2;
plot3(x,y,z)
%Time of flight
T =(2*vz0)/9.81
  2 件のコメント
Daniel M
Daniel M 2019 年 10 月 28 日
You have the values already. Remove the semi colon to see them in the command window.
Stephen Mixon
Stephen Mixon 2019 年 10 月 28 日
I just want the final values after the projectile lands and z=o, when I remove the semicolon is gives me hundreds of values for x, y, and z.

サインインしてコメントする。

回答 (1 件)

Daniel M
Daniel M 2019 年 10 月 28 日
編集済み: Daniel M 2019 年 10 月 28 日
If you want the end value, then do
coord = [x(end) y(end) z(end)]
If you want the value when z = 0, assuming it equals exactly zero,
ind = find(z==0,1,'last');
coord = [x(ind) y(ind) z(ind)]
If you want the closest data point to zero,
[~,ind] = min(abs(z));
If you want to choose the point graphically, select the data tip in the plot, right click and select export cursor to workspace.
  3 件のコメント
Daniel M
Daniel M 2019 年 10 月 28 日
Method 1 didn't work because you computed your answer for too long and z was negative at the end. Method 2 didn't work because you're not computed z at a timepoint when it equals exactly zero (except at the beginning). And method 3 didn't work because z = 0 at the beginning.
Daniel M
Daniel M 2019 年 10 月 28 日
編集済み: Daniel M 2019 年 10 月 28 日
There's a zillion ways to find x,y,z when z = 0 at the end of the trajectory.
If z(end) is positive, then increase t and keep computing, or use interp1 with the 'extrapolate' option.
If z(end) is negative, you can use
find(diff(sign(z)))
to find the locations of the zero crossings. From there you can also choose to interpolate the values to get the values when z=0.
Or you can use method 3 from above, but only after the trajectory has peaked.
[~,locmax] = max(z);
[closestToZero,locmin_tmp] = min(abs(z(locmax+1:end)));
locmin = locmax + locmin_tmp;
Or you can use your physics knowledge to solve for t when z = 0 and compute the solution at that time.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangePolar Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by