i need the second plot to start from where the last point on the first plot left off. The graph is meant to be continuous across all three stages not broken up. Help please?

16 次查看(过去 30 天)
close all
clc;
%define variables
mi_1=2290000;
mf_1=130000;
tb_1=165;
Isp_1=263;
mi_2=496200;
mf_2=40100;
tb_2=360;
Isp_2=421;
mi_3=123000;
mf_3=13500;
tb_3=500;
Isp_3=421;
g=9.81; %acceleration due to gravity
%stage 1
t_1=linspace(0,165);
mr_1=mi_1-((mi_1-mf_1)*(t_1/tb_1));
u_1=g.*(Isp_1.*log(mi_1./mr_1)-t_1); %velocity function
a_1=gradient(u_1, t_1(2)-t_1(1)); %differentiation of velocity function to get acceleration
p_1= cumtrapz(t_1,u_1); %integration of velocity function to get position
%end of stage 1
%stage 2
t_2=linspace(165,525);
mr_2=mi_2-((mi_2-mf_2)*(t_2/tb_2));
u_2=g.*(Isp_2.*log(mi_2./mr_2)-t_2);
a_2=gradient(u_2, t_2(2)-t_2(1));
p_2= cumtrapz(t_2,u_2);
%end of stage 2
%stage 3
t_3=linspace(525,1025);
mr_3=mi_3-((mi_3-mf_3)*(t_3/tb_3));
u_3=g.*(Isp_3.*log(mi_3./mr_3)-t_3);
a_3=gradient(u_3, t_3(2)-t_3(1));
p_3= cumtrapz(t_3,u_3);
%end of stage 3
%position-time graph
figure
plot(t_1,p_1,'blue',t_2,p_2,'blue',t_3,p_3,'blue')
title('Position')
ylabel('height[m]')
xlabel('time[s]')

采纳的回答

Dhananjay Kumar
Dhananjay Kumar 2019-12-4
Just shift the plot by adding the previous segment's final y-value:
plot(t_1,p_1,'blue',t_2,p_2+p_1(end),'blue',t_3,p_3+p_1(end)+p_2(end),'blue')

更多回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by