MSIZE=100
reftype=0
ident(2,2)=0
fid1= fopen('MSTRPIN.txt','rt');
if fid1 < 0
fprintf('error opening file\n');
return;
end
fid2= fopen('MYPULDAT.txt','w+t');
if fid2 < 0
fprintf('error opening file2\n');
return;
end
PI=4.0*atan(1.0);
V0=2.997925e8;
V02=V0*V0;
EPS=1.0/(V02*4.e-7*PI);
FAC=1./(2.*PI*EPS);
CMTM=2.54E-5;
for i=1:MSIZE
for j=1:MSIZE
ident(i,j)=0.0;
ident(i,i)=1.0;
end
end
line_number = 1;
oneline{line_number} = fgetl(fid1);
while ischar(oneline{line_number})
line_number = line_number + 1;
oneline{line_number} = fgets(fid1);
end
fclose(fid1);
for i=1:line_number-1
Data_1(i,1) = sscanf(oneline{i}(1:3),'%f,');
end
n = Data_1(1,1);
ncdiv= Data_1(2,1);
w = Data_1(3,1);
sep = Data_1(4,1);
t = Data_1(5,1);
er = Data_1(6,1);
w =w*CMTM;
sep =sep*CMTM;
t =t*CMTM;
DELTA=w/double(ncdiv)
%%%%%%%%%Without Dielectric*%%%%%%%%%%%%%%%
%%%%%%%%%Fill A1%%%%%%%%%%%%%%%%%%%%%%%%%%%
dist=0.0;
for i=1:ncdiv
A(1,i)=PHI(dist)
A(i,1)=A(1,i);
dist=dist+DELTA;
end
上面的脚本正在调用PHI(。)函数:
function ret= PHI( D )
global FAC ;
global DELTA;
global t;
DOW=2.0*D./DELTA
TOW=4.0*t./DELTA
DOWM=DOW-1.0
DOWP=DOW+1
if(D==0)
ret=FAC*(0.5*log(1.0+TOW*TOW)+TOW*atan(1.0./TOW))
else
ret=DOWM*log(DOWM)DOWP*log(DOWP)-0.5*DOWM*log(DOWM^2+TOW^2)+
0.5*DOWP*log(DOWP^2+TOW^2)-TOW*(atan(DOWM/TOW)-atan(DOWP/TOW))
ret=FAC/2.0
end
end
但是当脚本运行时发生错误: 订阅的分配维度不匹配。
widesefor错误(第62行) A(1,I)= PHI(DIST)
当我在函数中手动为D输入变量赋值时,不会发生错误。是什么原因?
答案 0 :(得分:0)
在PHI函数中,存在全局变量declerations:FAC,DELTA,t。
要与脚本文件共享这些变量,还必须声明相同的变量
as&#34; GLOBAL&#34;在脚本和函数定义中。
在错误情况下,DELTA和t未在函数
中正确初始化文件因为缺少&#39; GLOBAL&#39;脚本文件中的声明。