필터 지우기
필터 지우기

Two lines populated from one plot

조회 수: 2 (최근 30일)
Kailin Johnsson
Kailin Johnsson 2020년 11월 10일
댓글: Kailin Johnsson 2020년 11월 11일
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
  댓글 수: 1
Kailin Johnsson
Kailin Johnsson 2020년 11월 11일
This has solved the problem! Thank you!!!!

댓글을 달려면 로그인하십시오.

추가 답변 (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