How do I alter the curve of my plot

2 次查看(过去 30 天)
Thomas
Thomas 2023-10-8
评论: Sam Chak 2023-10-8
% Set variables: g is gravity, v is velocity, i_h is initial height, h_f is final height
g = 9.81;
v = 85;
i_h = 0:0.25:95;
h_f = 0
% Equations: t being time and d being distance
t = sqrt(2*i_h\g);
d = (85*sqrt(2*i_h/g));
figure;
plot(d,i_h)
title 'i_h'
ylabel ('Height (m)')
xlabel ('Distance (m)')
grid on
How do I get my graph to start at coordinates 0, 95 and end at coordinates, 374.077, 0?

回答(1 个)

Sam Chak
Sam Chak 2023-10-8
g = 9.81;
v = 85;
i_h = 0:0.25:95;
h_f = 0;
% Equations: t being time and d being distance
t = sqrt(2*i_h\g);
d = (85*sqrt(2*i_h/g));
figure;
plot(d, i_h(end)-i_h, 'linewidth', 2)
title 'i_h'
ylabel ('Height (m)')
xlabel ('Distance (m)')
grid on
  2 个评论
Thomas
Thomas 2023-10-8
Could you explain this line of code: 'i_h(end)-i_h, 'linewidth', 2)'?
Sam Chak
Sam Chak 2023-10-8
Alright @Thomas, i_h(end) is 95 m, and i_h is a vector array ranging from 0 to 95. Previously, the figure was plotted with i_h as the y-axis variable and d as the x-axis variable, using the syntax "plot(d, i_h)". This resulted in the graph starting from (0, 0).
In the image you provided, it seems you want to plot the graph starting from the highest point, which naturally means you want to plot from 95 m down to 0 (ground level). One way to achieve this is by defining a new y-axis variable, like ynew = 95 - i_h, and then plotting it using "plot(d, ynew)".

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

标签

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by