MATLAB运行程序时出现??? Index exceeds matrix dimensions错误
MATLAB运行程序时出现??? Index exceeds matrix dimensions错误,下面是程序,麻烦大家帮我看看好吗,多谢大家了!%以不同文化资源增长变化率下文化创意产业集群规模演化模拟为例
clear all; n=20; cmax=1500; time=100; s=zeros(n,n);
s((n-2)/2:(n-2)/2+1,(n-2)/2:(n-2)/2+1)=ones(2,2);
R0=0.8; s0=s; r=rand(n); t=1; stsum1(t)=0;
for i=1:n, for j=1:n
st{t}=s0; a=0.2; socv=0.4; labv=6; serv=0.4; polv=6; marv=0.4;
e1{t}=1./(1+100*exp(-a.*(stsum1(t))));
e2{t}=1./(1+100*exp(-socv.*t));
e3{t}=1./(1+100*exp(-labv.*4*(t/time)*(1-t/time)));
e4{t}=1./(1+100*exp(-serv.*t));
e5{t}=1./(1+100*exp(-polv.*4.*(t/time)*(1-t/time)));
e6{t}=1./(1+100*exp(-marv.*t));
e{t}= e1{t}.* e2{t}.* e3{t}.*e4{t}.* e5{t}.* e6{t};
p=0.2; f{t}=1./(1+100*exp(-p.*(stsum1(t))));
R{t}(i,j)=(1-stsum1(t)/cmax)* (1+e{t})*(1+f{t}(i,j));
if st{t}(i,j)>0, stsum1(t)=stsum1(t)+st{t}(i,j); end
end; end
t=2; stsum1(t)=0; a=0.2; socv=0.4;
labv=6; serv=0.4; polv=6; marv=0.4;
e1{t}=1-1./(1+100*exp(-a.*(stsum1(t-1))));
e2{t}=1./(1+100*exp(-socv.*t));
e3{t}=1./(1+100*exp(-labv.*4.*(t/time)*(1-t/time)));
e4{t}=1./(1+100*exp(-serv.*t));
e5{t}=1./(1+100*exp(-polv.*4.*(t/time)*(1-t/time)));
e6{t}=1./(1+100*exp(-marv.*t));
e{t}= e1{t}.* e2{t}.* e3{t}.*e4{t}.* e5{t}.* e6{t};
p=0.2; f{t}=1./(1+100*exp(-p.*(stsum1(t-1)))); pnt{t-1}=pernei(st{t-1},n);
for i=1:n, for j=1:n
if stsum1(t-1)==cmax, R{t}(i,j)=0.1.*(1+e{t})*(1+f{t}(i,j));
else R{t}(i,j)=(1-stsum1(t)/cmax)* (1+e{t})*(1+f{t}(i,j));
end
end; end
for i=1:n, for j=1:n
if R{t}(i,j)>=R0&R{t}(i,j)>=r{t-1}(i,j)&pnt{t-1}(i,j)>=0&r(i,j)>=0.3
st{t}(i,j)=st{t-1}(i,j)+1;
elseif R{t}(i,j)>=R0&R{t}(i,j)>=r{t-1}(i,j)&pnt{t-1}(i,j)<0
st{t}(i,j)= st{t-1}(i,j);
elseif R{t}(i,j)>=R0&R{t}(i,j)<r{t-1}(i,j)&r(i,j)>=0.3
st{t}(i,j)= st{t-1}(i,j);
elseif R{t}(i,j)<R0, st{t}(i,j)= st{t-1}(i,j)-1;
end
if st{t}(i,j)<0, st{t}(i,j)=0; end
stsum1(t)=stsum1(t)+st{t}(i,j);
end; end
for t=3:time
stsum1(t)=0; a=0.2; socv=0.4; labv=6; serv=0.4; polv=6; marv=0.4;
e1{t}=1./(1+100*exp(-a.*(stsum1(t-1))));
e2{t}=1./(1+100*exp(-socv.*t));
e3{t}=1./(1+100*exp(-labv.*4*(t/time)*(1-t/time)));
e4{t}=1./(1+100*exp(-serv.*t));
e5{t}=1./(1+100*exp(-polv.*4.*(t/time)*(1-t/time)));
e6{t}=1./(1+100*exp(-marv.*t));
e{t}= e1{t}.* e2{t}.* e3{t}.*e4{t}.* e5{t}.* e6{t};
p=0.2; f{t}=1./(1+100*exp(-p.*(stsum1(t-1))));
pnt{t-1}=pernei(st{t-1},n);
for i=1:n, for j=1:n
if stsum1(t-1)==cmax, R{t}(i,j)=0.1*(1+e{t})*(1+f{t}(i,j));
else R{t}(i,j)=(1-stsum1(t)/cmax)* (1+e{t})*(1+f{t}(i,j));
end
end; end
for i=1:n, for j=1:n
if R{t}(i,j)>=R0&R{t}(i,j)>=r{t-1}(i,j)&pnt{t-1}(i,j)-pnt{t-2}(i,j)>=0&r(i,j)>=0.3
st{t}(i,j)= st{t-1}(i,j)+1;
elseif R{t}(i,j)>=R0&R{t}(i,j)>=r{t-1}(i,j)&pnt{t-1}(i,j)-pnt{t-2}(i,j)<0
st{t}(i,j)= st{t-1}(i,j);
elseif R{t}(i,j)>=R0&R{t}(i,j)<r{t-1}(i,j) &r(i,j)>=0.3
st{t}(i,j)= st{t-1}(i,j);
elseif R{t}(i,j)<R0, st{t}(i,j)= st{t-1}(i,j)-1;
end
if st{t}(i,j)<0, st{t}(i,j)=0; end
stsum1(t)=stsum1(t)+st{t}(i,j);
end; end
st{t}; pnt{t+1}=pernei(st{t},n); pnt{t+1};
end
t=1:time;
plot(t,stsum1)
title('文化创意产业集群规模演化')
xlabel('模拟次数');ylabel('集群资产总量')
legend('a=0.2')
[ 本帖最后由 ChaChing 于 2009-12-26 23:22 编辑 ]
回复 楼主 feirfei 的帖子
Ref :12F, 常见的程序出错问题整理 (eight)
http://forum.vibunion.com/forum/thread-46001-1-1.html
回复 沙发 ChaChing 的帖子
非常感谢您的回复! 我看了您提示我看的帖子了,可是我还是找不出错来,我是新手,麻烦您再帮我看看好吗? 我一部分一部分的运行,运行一开始的一部分就出现??? Index exceeds matrix dimensions错误了,麻烦您帮我找找这一小段的错误在哪好吗,麻烦了,非常非常感谢clear all
n=20;
cmax=1500;
time=100;
s=zeros(n,n);
s((n-2)/2:(n-2)/2+1,(n-2)/2:(n-2)/2+1)=ones(2,2);
R0=0.8;
s0=s;
r=rand(n);
t=1;
stsum1(t)=0;
for i=1:n
for j=1:n
st{t}=s0;
a=0.2 ;
socv=0.4;
labv=6;
serv=0.4;
polv=6;
marv=0.4;
e1{t}=1./(1+100*exp(-a*(stsum1(t))));
e2{t}=1./(1+100*exp(-socv*t));
e3{t}=1./(1+100*exp(-labv*4*(t/time)*(1-t/time)));
e4{t}=1./(1+100*exp(-serv*t));
e5{t}=1./(1+100*exp(-polv*4*(t/time)*(1-t/time)));
e6{t}=1./(1+100*exp(-marv*t));
e{t}= e1{t}* e2{t}* e3{t}*e4{t}* e5{t}* e6{t};
p=0.2;
f{t}=1./(1+100*exp(-p*(stsum1(t))));
R{t}(i,j)=(1-stsum1(t)/cmax)* (1+e{t})*(1+f{t}(i,j));
if st{t}(i,j)>0
stsum1(t)=stsum1(t)+st{t}(i,j);
end
end
end
回复 板凳 feirfei 的帖子
??? Attempted to access f.%cell(1,2); index out of bounds because numel(f.%cell)=1.Error in ==> zzz at 30
R{t}(i,j)=(1-stsum1(t)/cmax)* (1+e{t})*(1+f{t}(i,j));
t=1; f{t}是1*1的cell, 那来的f{t}(1,2)?
还有LZ用了一堆cell, 而且都是1*1, 有必要吗?
回复 地板 ChaChing 的帖子
非常感谢您的回复和帮助,我再好好看看,多谢了,非常感谢回复 地板 ChaChing 的帖子
您好,很不好意思,我知道R{t}(i,j)=(1-stsum1(t)/cmax)* (1+e{t})*(1+f{t}(i,j));中f{t}(i,j)可能是错的,但我把f{t}(i,j)中的(i,j)去掉后,整个式子变成R{t}(i,j)=(1-stsum1(t)/cmax)* (1+e{t})*(1+f{t});后,在后面t=2一段程序运行时又出现??? Cell contents reference from a non-cell array object.错误,麻烦您帮我看看怎么改好吗,非常非常感谢! 我的整个程序在最上面, 分 t=1; t=2; t=3:time 三大部分
回复 6楼 feirfei 的帖子
个人水平有限, 实在无法子细看懂LZ的程序!:@LLZ一定得让想帮的人知道LZ要什么!
还有LZ循环中(for i=1:n, for j=1:n), st/e1/e2...根本没变化, 有需要摆在循环中吗?
[ 本帖最后由 ChaChing 于 2009-12-29 00:53 编辑 ]
页:
[1]