Plot Error -- Vectors must be the same lengths
Mostra commenti meno recenti
%Adult Bison Fecundity changed
fprintf('Adult Dominant Equilibrium Structure \n')
fprintf('Fecundity Eigenvalue Calves Yearlings Adults \n')
fprintf('----------------------------------------------- \n')
f=[0.2 0.42 1.0 1.4];
for i = 1:length(f)
A = [0.0 0.0 f(i);0.6 0.0 0.0;0.0 0.75 0.95];
[v,lambda] = eig(A);
lambdavector = max(lambda);
for j = 1:length(lambdavector)
if max(max(abs(lambda))) == abs(lambdavector(j))
loc = j;
deig = lambda(j,j);
end
end
normv(:,i) = v(:,loc)/sum(v(:,loc));
fprintf('adult fecundity value',f(i))
fprintf('dominant eigenvalue',deig)
fprintf('calve proportion at eg',normv(1,i))
fprintf('yearling proportion at eg',normv(2,i))
fprintf('adult proportion at eg',normv(3,i))
fprintf('\n')
end
h = normv(1,:);
j = normv(2,:);
a = normv(3,:);
plot(f,h,'r.-',f,j,'g.-',f,a,'b.-')
legend('calves','yearlings','adults')
xlabel('Adult Fecundity')
ylabel('Equilibrium Structure')
title('Adult Fecundity Changed')
This is my m-file, calculating how a population changes when one of the values in a Leslie matrix is changed. Every time I run it though I get the graph error telling me my vectors must be the same lengths. Am I overlooking something or is there a bigger problem with my m-file? Thanks!
Risposte (1)
Walter Roberson
il 4 Apr 2013
When I copy your code into my MATLAB session, I do not get an execution time error message.
I do see that you have not coded your fprintf() properly. Try
fprintf('adult fecundity value %f, dominant eigenvalue %f, calve proportion at eg %f, yearling proportion at eg %f, adult proportion at eg %f\n',f(i), deig, normv(1,i), normv(2,i), normv(3,i) );
The key change of which is the %f rather than putting it all in one call. (Putting it all in one call makes it cleaner to write the delimiters in-between the fragments.)
Categorie
Scopri di più su Polar Plots in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!