フィルターのクリア

Error using plot Vectors must be the same lengths.

2 ビュー (過去 30 日間)
Todd
Todd 2013 年 11 月 10 日
コメント済み: Peyman 2014 年 3 月 16 日
So my code will run just fine when I first boot up MatLab. But if I try to run it again, I always get this message "Error using plot Vectors must be the same lengths." Is this a computer memory issue on my end or something?
MatLab Version: 8.1.0.604 (R2013a)
t=[0 .3 .5 .75 .95 .99];
for i = 1:length(t)
A = [0.0 0.0 .42;.6 0.0 0.0;0.0 0.75 t(i)];
[v,lambda] = eig(A);
lambdavector = max(lambda);
for y = 1:length(lambdavector)
if max(max(abs(lambda))) == abs(lambdavector(y))
loc = y;
deig = lambda(y,y);
end
end
normv(:,i) = v(:,loc)/sum(v(:,loc));
end
c = normv(1,:);
y = normv(2,:);
a = normv(3,:);
figure
plot(t,c,'b.-',t,y,'g.-',t,a,'r.-')
xlabel('Adult Survival Rate')
ylabel('Equilibrium Population')
title('Adult Survival Changed')
legend('Calves','Yearlings','Adults')

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 11 月 10 日
編集済み: Azzi Abdelmalek 2013 年 11 月 10 日
Maybe some previous result are interfering with your code, try this
clear
t=[0 .3 .5 .75 .95 .99];
for i = 1:length(t)
A = [0.0 0.0 .42;.6 0.0 0.0;0.0 0.75 t(i)];
[v,lambda] = eig(A);
lambdavector = max(lambda);
for y = 1:numel(lambdavector)
if max(abs(lambda(:))) == abs(lambdavector(y))
loc = y;
deig = lambda(y,y);
end
end
normv(:,i) = v(:,loc)/sum(v(:,loc));
end
c = normv(1,:);
y = normv(2,:);
a = normv(3,:);
figure
plot(t,abs(c),'b.-',t,abs(y),'g.-',t,abs(a),'r.-')
xlabel('Adult Survival Rate')
ylabel('Equilibrium Population')
title('Adult Survival Changed')
legend('Calves','Yearlings','Adults')
Some of your data are complex numbers, I replaced them by their modulus
You can also replace max(max(A)) by max(A(:))
  2 件のコメント
Todd
Todd 2013 年 11 月 10 日
That worked thank you!
Peyman
Peyman 2014 年 3 月 16 日
I had a similar issue. I ran the code after about a week and this error showed up. I just added "clear" at the beginning of each section of my code and it worked again.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Object Programming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by