Afficher commentaires plus anciens
A = [ 0 0 0.43; 0.6 0 0; 0 0.75 0.96 ];
T = [ 1 2 3 4 5 10 20 25 50 75 ];
V0 = [ 42, 0, 95 ]';
V=zeros(3,length(T));
V(:,1)=V0;
i=0;
for t=T
i=i+1;
V(:,1)=(A^t)*V0;
end
figure
T=[0 1 2 3 4 5 10 20 25 50 75];
T2=log(T);
V2=log(V);
LINE 22 plot( T2, V2(1,:), 'b', T2, V2(2,:), 'g', T2, V2(3,:), 'r')
%legend('calves','yearlings','adults')
title('population versus time')
xlabel('time')
LINE 30 ylabel('population')
THAT ERROR WENT AWAY. NOW IT SAYS....
??? Error using ==> plot Vectors must be the same lengths.
Error in ==> project3 at 22 plot( T2, V2(1,:), 'b', T2, V2(2,:), 'g', T2, V2(3,:), 'r')
1 commentaire
Image Analyst
le 22 Nov 2011
Try this:
V0 = [ 42; 0; 95 ]
V=zeros(3,length(T)+1);
V(:,1)=V0;
col = 1;
for t=T
col = col+1;
V(:, col)=(A.^t)*V0;
end
Réponse acceptée
Plus de réponses (2)
Image Analyst
le 22 Nov 2011
Well I think
figure T=[0 1 2 3 4 5 10 20 25 50 75];
evaluates to
figure 0 1 2 3 4 5 10 20 25 50 75;
and you don't have figures with those ID numbers. Try putting a semicolon after figure or splitting that line into two lines.
4 commentaires
Haley
le 22 Nov 2011
Haley
le 22 Nov 2011
Image Analyst
le 22 Nov 2011
OK, I see you now edited it so that figure is on a separate line but I don't get the error you did. When I run your code it says
??? Error using ==> mtimes
Inner matrix dimensions must agree.
Error in ==> test at 11
V(:,1)=(A^t)*V0;
Did you perhaps mean A .^ t to do an element-by-element raising to a power?
Haley
le 22 Nov 2011
Haley
le 23 Nov 2011
0 votes
8 commentaires
Image Analyst
le 23 Nov 2011
Yes, the debugger can be a more powerful tool than "Answers." Glad you learned how to use it.
Michael Roberts
le 5 Avr 2017
please help; how did you figure it out?
Michael Roberts
le 5 Avr 2017
my plot is still blank, can someone please tell me how to get something to show up in my plot
Image Analyst
le 5 Avr 2017
To get something to show up in your plot, use the plot() function. That's about all we can say unless we see your code. If you want more help, read this first then start a new question.
Michael Roberts
le 5 Avr 2017
Modifié(e) : Walter Roberson
le 5 Avr 2017
to clarify: i have gotten this far in my code, but my plot is still empty. my code is
A = [ 0 0 0.43; 0.6 0 0; 0 0.75 0.96 ];
T = [ 1 2 3 4 5 10 20 25 50 75 ];
V0 = [ 42, 0, 95 ]';
V=zeros(3,length(T));
V(:,1)=V0;
i=0;
for t=T
i=i+1;
V(:,1)=(A^t)*V0;
end
figure
T=[0 1 2 3 4 5 10 20 25 50 75];
%legend('calves','yearlings','adults')
title('population versus time')
xlabel('time')
ylabel('population')
I just can't figure out why my plot is blank
Walter Roberson
le 5 Avr 2017
A = [ 0 0 0.43; 0.6 0 0; 0 0.75 0.96 ];
T = [ 0 1 2 3 4 5 10 20 25 50 75 ];
V0 = [ 42, 0, 95 ]';
V=zeros(3,length(T));
for i = 1 : length(T)
V(:,i)=(A^T(i))*V0;
end
figure
T2=log(T);
V2=log(V);
plot( T2, V2(1,:), 'b', T2, V2(2,:), 'g', T2, V2(3,:), 'r')
legend('calves','yearlings','adults')
title('population versus time')
xlabel('time')
ylabel('population')
Image Analyst
le 5 Avr 2017
It's blank because you didn't use plot() like I recommended. Walter did use it and so his code does show data.
Michael Roberts
le 5 Avr 2017
Thank you very much Walter and Mr. italicizing image analyst
Catégories
En savoir plus sur Annotations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!