各位大侠请教一下matlab文件运行的事情
>> function QQ=traffic2(t)%j代表方向东南西北分别取值为1,2,3,4;
%i为相位,取值i=1,2,3,4;
%l为车道,在右相位车道实时放行的情况下,l=1,2;
%k表示信号周期k=1,2,…K;(K=4)
%t(n,i)为第n个交叉路口、第i相位的持续时间;
%tm为排队车辆头车启动时间的损失时间;
tm=2;
%tc信号灯相互转换的损失时间
tc=5;
%车辆到达率q(n,j,l,i),n-交叉路口,j-方向,l-车道,i-相位
q=zeros(2,4,3,4);
q=q_generate;
%饱和车流率
q_baohe=ones(2,4,3,4)*6;
%道路路段最大车容量
Qr=100;
%判断矩阵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,还请高手多多指教。 估计是没主程序,没给变量吧~~~~
不知道,没试过 这个QQ函数的定义到什么地方结束呀?函数定义需要写在M文件中! I use t=3 to insert and run the procude;
there are servel problems;
first:it says undifined funtion ‘q_generate’;
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 (下标超出);
the problem what you said doesn't appear.
but if what you say is real then it means that "程序定义出错";
因为本人水平有限,暂时看不出来,:handshake if you can show all the procedure and the project,I think I am really willing to help you 把文件保存以后,在command window运行QQ=traffic2(t)
traffic2是函数,要调用
页:
[1]