Index Exceeds Matrix Dimensions
情報
この質問は閉じられています。 編集または回答するには再度開いてください。
古いコメントを表示
When I run the code below I get the error "index exceeds matrix dimensions' I'm trying to plot time on the x-axis and s,i,r on three plots. Thank you
pops=[s;i;r];
for n=1:run_count
for j=1:n
% loop to build up matrix of population values
lambda=mu*(totpop)+alpha*i;
news=s+lambda-beta*s*i-mu*s;
newi=i+beta*s*i-(alpha+k)*i-mu*i+p*r;
newr=r+k*i-mu*r-p*r;
s=news;
i=newi;
r=newr;
beta=normrnd(2.3e-9,2.3e-9*.1);
k=normrnd(1.417e-6,1.417e-6*.1);
p=normrnd(.0024,.0024*.1);
pops=[pops,[s;i;r]];
end
% plot result
subplot(3, 1, 1);
plot ([0:n],pops(1,:));
xlabel ('time');
ylabel ('susceptible');
hold on;
subplot(3, 1, 2);
plot ([0:n], pops(2,:));
xlabel ('time');
ylabel ('infected');
hold on;
subplot(3, 1, 3);
plot ([0:n],pops(3,:));
xlabel ('time');
ylabel ('recovered');
hold on;
if true
% code
end
end
0 件のコメント
回答 (1 件)
James Tursa
2017 年 6 月 15 日
You can use the debugger for this. First, type in the following at the command line:
dbstop if error
Then run your code. When the error is encountered, the code will pause at the offending line with all current variables intact. Then you can examine the size of the variables that are causing the problem. Backtrack in your code to figure out why the sizes and/or indexes are not what you expected at that line.
0 件のコメント
この質問は閉じられています。
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!