%判断矩阵h(n,j,l,i),n-交叉路口,j-方向,l-车道,i-相位
h=zeros(2,4,3,4);
h(1,2,3,3)=1;
h(1,3,2,1)=1;
h(1,4,1,4)=1;
h(2,1,2,1)=1;
h(2,2,1,4)=1;
h(2,2,3,3)=1;
h(2,3,2,1)=1;
h(2,4,1,4)=1;
h(2,4,3,3)=1;
%判断矩阵p(n,j,l,i),n-交叉路口,j-方向,l-车道,i-相位
p=zeros(2,4,3,4);
p(1,2,1,4)=1;
p(1,2,2,3)=1;
p(1,2,3,3)=1;
p(1,3,1,2)=1;
p(1,3,2,1)=1;
p(1,3,3,1)=1;
p(1,4,1,4)=1;
p(1,4,2,3)=1;
p(1,4,3,3)=1;
p(2,1,1,2)=1;
p(2,1,3,1)=1;
p(2,2,2,3)=1;
p(2,2,3,3)=1;
p(2,3,1,2)=1;
p(2,3,2,1)=1;
p(2,3,3,1)=1;
p(2,4,1,4)=1;
p(2,4,2,3)=1;
for k=1:20
Q(k)=0;
DVw_z(k)=0;
QQ=0;
%------------到达车辆-------------------------------------------------
AVw(k)=0;
AVr(k)=0;
AVr1=0;
AVr2=0;
AVr3=0;
for n=1:2
for j=1:4
for l=1:3
for i=1:4
x=n*i;
%(一)未进入道路路段的车辆数
AVw=AVw+floor(abs(h(n,j,l,i)-1))*q(n,j,l,i)*t(x);
%(二)流入系统道路的到达车辆数
%第一种情况
AVr1=AVr1+h(n,j,l,i)*q(n,j,l,i)*(t(x)-tm-tc);
%第二种情况
AVr2=AVr2+h(n,j,l,i)*q_baohe(n,j,l,i)*t(x);
%第三种情况
if k==1
AVr3=Qr;
else
AVr3=Qr-Q(k-1);
end
end
end
end
end
AVr(k)=min(min(AVr1,AVr2),AVr3);
%-------------离开车辆--------------------------------------------
DVw(k)=0;
DVw1=0;
DVw2=0;
DVr(k)=0;
DVr1=0;
DVr2=0;
for n=1:2
for j=1:4
for l=1:3
for i=1:4
x=n*i;
%(一)未经由系统路段直接离开的车辆数
DVw1=p(n,j,l,i)*q_baohe(n,j,l,i)*t(x);
if k==1
DVw2=AVw(k);
else
DVw2=DVw_z(k-1)+AVw(k);
end;
%(二)经由系统路段离开的车辆数
DVr1=floor(abs(p(n,j,l,i)-1))*q_baohe(n,j,l,i)*t(x);
if k==1
DVr2=AVr(k);
else
DVr2=AVr(k)+Q(k-1);
end
end
end
end
end
DVw(k)=min(DVw1,DVw2);
DVr(k)=min(DVr1,DVr2);
%------- 滞留车辆------
Q(k)=AVr(k)-DVr(k);
DVw_z(k)=AVw(k)-DVw(k);
QQ=Q(k)+DVw_z(k);
end
??? function QQ=traffic2(t)
|
Error: Function definitions are not permitted at the prompt or in scripts.
将别人的matlab程序直接拷入运行后出现上面红色提示,请问该如何解决?
程序是2008年研究生数学建模比赛B题的一段,完整的。
刚开始练习使用matlab,还请高手多多指教。作者: zjqylcy 时间: 2009-8-8 16:31
估计是没主程序,没给变量吧~~~~
不知道,没试过作者: madio 时间: 2009-8-8 18:07
这个QQ函数的定义到什么地方结束呀?函数定义需要写在M文件中!作者: 追梦者 时间: 2009-8-8 20:29
I use t=3 to insert and run the procude;
there are servel problems;
first:it says undifined funtion ‘q_generate’[in your line 13];
then I chang your line 13 with q_generate=q;(but I don't really know what this mean)
it shows the problem that index out (下标超出)[in your line 65];
the problem what you said doesn't appear.
but if what you say is real then it means that "程序定义出错";
因为本人水平有限,暂时看不出来,作者: 追梦者 时间: 2009-8-8 20:32
if you can show all the procedure and the project,I think I am really willing to help you作者: vvv 时间: 2009-8-9 13:58
把文件保存以后,在command window运行QQ=traffic2(t)
traffic2是函数,要调用