Filter löschen
Filter löschen

How do I alter the curve of my plot

2 Ansichten (letzte 30 Tage)
Thomas
Thomas am 8 Okt. 2023
Kommentiert: Sam Chak am 8 Okt. 2023
% 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?

Antworten (1)

Sam Chak
Sam Chak am 8 Okt. 2023
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 Kommentare
Thomas
Thomas am 8 Okt. 2023
Could you explain this line of code: 'i_h(end)-i_h, 'linewidth', 2)'?
Sam Chak
Sam Chak am 8 Okt. 2023
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)".

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by