Borrar filtros
Borrar filtros

Two lines populated from one plot

2 visualizaciones (últimos 30 días)
Kailin Johnsson
Kailin Johnsson el 10 de Nov. de 2020
Comentada: Kailin Johnsson el 11 de Nov. de 2020
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 comentario
David Hill
David Hill el 10 de Nov. de 2020
Get rid of the hold on. Also you do not need the figure() command.

Iniciar sesión para comentar.

Respuesta aceptada

VBBV
VBBV el 10 de Nov. de 2020
Change this line from
E4 = a1*(p3)/(1+(p3/b2)) % before
to
E4 = a1*(p3)./(1+(p3/b2)) % after
and plot again
  1 comentario
Kailin Johnsson
Kailin Johnsson el 11 de Nov. de 2020
This has solved the problem! Thank you!!!!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by