Two lines populated from one plot

2 次查看(过去 30 天)
Hello,
I am working on a simple MATLAB code, and I have come across an interesting problem. I have populated multiple lines on the same graph, however when entering the last data point (red) two have populated... I have attached a picture and the code below, if anyone has any ideas why this is incorrect, please let me know! Thanks!
%Malthusian Growth Model
% Time interval
% t = (1790:10:2010)';
% Previous population
Pn = [2.91 3.929 5.308 7.239 9.638 12.866 17.069 23.191 31.443 39.818 50.189 62.947 76.212 92.228 106.021 122.775 132.164 150.697 179.323 203.302 226.545 248.709 281.421]';
% Growth Rate Assumption
R = (0.349+1)';
%Malthusian Model
E = (Pn*R)';
% Discrete Logistic Model
% Parameter and intial condtions
r= (0.349);
% Carrying Capactiy
M= 451.7;
X0= 3.929;
p= [2.913 3.929 5.308 7.239 9.638 12.866 17.069 23.191 39.818 50.189 62.947 76.212 92.228 106.021 122.775 132.164 150.697 179.323 203.302 226.545 248.709 281.421 308.745]';
% For loop to generate seqeunce terms
for i=1:length(p)
F(i)=p(i)+r*p(i)*(1-p(i)/M)';
end
tBegin = 1790; % time begin
tEnd = 2010; % time end
% Beverton-Holt Model
% Parameter and intial condtions
Pe= 486.8
a1= 1.23065
b2= 2110.5
p3= [2.913 3.929 5.308 7.239 9.638 12.866 17.069 23.191 39.818 50.189 62.947 76.212 92.228 106.021 122.775 132.164 150.697 179.323 203.302 226.545 248.709 281.421 308.745]';
% Bevholt equation
E4 = a1*(p3)/(1+(p3/b2))
% Time Interval
% a=(1790:10:2010)';
% Population
b= [3.929 5.308 7.239 9.638 12.866 17.069 23.191 31.443 39.818 50.189 62.947 76.212 92.228 106.021 122.775 132.164 150.697 179.323 203.302 226.545 248.709 281.421 308.745]';
Data = b;
Labels2 = [1790:10:1860]';
Labels = [1790:10:2010]';
% Plot all models 1790-2010
figure
plot(Labels,Data,'k-*',Labels,E,'b-*',Labels,F,'m-*', Labels,E4,'r-*')
title('Comparison of Models of US Census Data, 1790-2010')
legend('Data','Malthusian','Discrete Logistic','Beverton-Holt Model')
axis([1780 2020 0 400])
hold on
  1 个评论
David Hill
David Hill 2020-11-10
Get rid of the hold on. Also you do not need the figure() command.

请先登录,再进行评论。

采纳的回答

VBBV
VBBV 2020-11-10
Change this line from
E4 = a1*(p3)/(1+(p3/b2)) % before
to
E4 = a1*(p3)./(1+(p3/b2)) % after
and plot again

更多回答(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