Why does my attempt to plot keep resulting in a "Vectors must be the same lengths" error?
1 view (last 30 days)
Show older comments
I have tried writing this code a couple of ways and keep producing the same error: "Plot: Vectors must be the same lengths." I am relatively new to Matlab.
Pop0 = [0.2 0.42 1.0 1.4 5 6 7 8]
format shortg
for i = 1:length(Pop0)
A = [0 0 Pop0(i); .6 0 0; 0 .75 .95]
[v,lambda] = eig(A)
lambdavector = max(lambda);
for b1 = 1:length(lambdavector)
if max(max(abs(lambda))) == abs(lambdavector(b1))
loc = b1;
deig = lambda(b1,b1);
end
end
normv(:,i) = v(:,loc)/sum(v(:,loc));
end
a1 = normv(1,:);
b1 = normv(2,:);
c1 = normv(3,:);
plot(Pop0,a1, 'r', Pop0,b1, 'g', Pop0,c1, 'b')
xlabel('Adult Fecundity')
ylabel('Equilibrium Structure')
0 Comments
Accepted Answer
Image Analyst
on 13 Nov 2013
Set a breakpoint at the plot line, and hover your cursor over Pop0, a1, b1, and c1. You'll see that they're not all the same length. If you don't know what I'm talking about, see this excellent link: http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/
That said, I copied and pasted your code and it ran fine - no error message whatsoever !
0 Comments
More Answers (0)
See Also
Categories
Find more on Line Plots 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!