Unrecognized Variable when running a graph
6 views (last 30 days)
Show older comments
Kailin Johnsson
on 10 Nov 2020
Commented: Kailin Johnsson
on 10 Nov 2020
Hello,
I am tyring to run a very simple code, however every time I use the a variable in this locaiton on MatLab, it says the variable is not recognized despite being defined... any suggestions? When I run the code without multiple formulas input it works fine. Thanks!
0 Comments
Accepted Answer
David Hill
on 10 Nov 2020
Move your plot function below the line (31) where variable E is defined.
5 Comments
David Hill
on 10 Nov 2020
Your were clearing E!
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
% 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;
Labels = [1790:10:2010]';
% Plot all models 1790-2010
plot(Labels,Data,'k-*',Labels,E,'b-*',Labels,F,'m-*');
title('Comparison of Models of US Census Data, 1790-2010');
legend('Data','Malthusian','Discrete Logistic');
axis([1780 2020 0 500]);%changed axis to more appropriate
More Answers (0)
See Also
Categories
Find more on Graphics Object Identification in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!