Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 工程数学软件 > MATLAB论坛
MATLAB论坛 一切MATLAB相关问题在此讨论。
 
 
主题工具 显示模式
旧 2009-04-10, 10:28   #1
世界杯
初级会员
 
注册日期: 2009-04-10
帖子: 2
声望力: 0
世界杯 正向着好的方向发展
默认 关于matlab数组的程序问题

[filename,filepath]=uigetfile('h1.txt','Select Input file');
file=[filepath filename];
fid=fopen(file,'rt');
if fid==-1
('Error opening the file')
end
while 1
nextline=fgetl(fid);
if~isstr(nextline), break, end
disp(nextline);
h1=sscanf(nextline, ' %f %f ');
end
[filename,filepath]=uigetfile('h2.txt','Select Input file');
file=[filepath filename];
fid=fopen(file,'rt');
if fid==-1
('Error opening the file')
end
while 1
nextline=fgetl(fid);
if~isstr(nextline), break, end
disp(nextline);
h2=sscanf(nextline, ' %f %f ');
end
[filename,filepath]=uigetfile('n1.txt','Select Input file');
file=[filepath filename];
fid=fopen(file,'rt');
if fid==-1
('Error opening the file')
end
while 1
nextline = fgetl(fid);
if~isstr(nextline), break, end
disp(nextline);
n1=sscanf(nextline, ' %f %f ');
end
[filename,filepath]=uigetfile('n2.txt','Select Input file');
file=[filepath filename];
fid=fopen(file,'rt');
if fid==-1
('Error opening the file')
end
while 1
nextline=fgetl(fid);
if~isstr(nextline), break, end
disp(nextline);
n2=sscanf(nextline, ' %f %f ');
end
E0=8.85*10^-12
u0=1.26*10^-6
y0=sqrt(E0/u0)
lam=6*10^-7
x=0.5
M=[1,0;0,1]
N=3
for i=1:N
de1=2*3.14/lam*n1(i)*h1(i)*cos(x)
de2=2*3.14/lam*n2(i)*h2(i)*cos(x)
m111=cos(de1)
m221=cos(de1)
m211=j*y0*n1(i)*sin(de1)
m121=j/(y0*n1(i))*sin(de1)
m112=cos(de2)
m222=cos(de2)
m212=j*y0*n2(i)*sin(de2)
m122=j/(y0*n2(i))*sin(de2)
A=[m111,m121;m211,m221]*[m112,m122;m212,m222]
M=M*A
end
n0=1.2
ns=1.3
Y0=n0*y0
Ys=ns*y0
M11=M(1,1)
M12=M(1,2)
M21=M(2,1)
M22=M(2,2)
r=(Y0*M11+Y0*Ys*M12-M21-Ys*M22)/ (Y0*M11+Y0*Ys*M12+M21+Ys*M22)
R=r*conj(r)

h1:1.5*10^-7 3*10^-7 2.3*10^-7
h2:2*10^-7 1.8*10^-7 3.4*10^-7
n1:1.2 1.7 1.5
n2:2 2.3 1.8
我用的matlab6.5
结果运行后出现Index exceeds matrix dimensions.
不知道是什么问题,请高手帮忙看看,谢谢
世界杯 当前离线   回复时引用此帖
 


发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛启用 表情符号
论坛启用 [IMG] 代码
论坛禁用 HTML 代码



所有时间均为北京时间。现在的时间是 11:04


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.