Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
|
![]() |
#1 |
初级会员
注册日期: 2009-04-10
帖子: 2
声望力: 0 ![]() |
![]()
[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. 不知道是什么问题,请高手帮忙看看,谢谢 |
![]() |
![]() |
![]() |
#2 |
高级会员
注册日期: 2008-11-01
年龄: 39
帖子: 406
声望力: 26 ![]() |
![]()
lz 能否把matlab提示的错误整个句子贴出来 包括出错位置等等
大家一起讨论一下 |
![]() |
![]() |
![]() |
#3 |
初级会员
注册日期: 2009-04-10
帖子: 2
声望力: 0 ![]() |
![]()
整个句子就是Index exceeds matrix dimensions
算完第一个循环的M后就报错了 |
![]() |
![]() |
![]() |
#4 |
高级会员
注册日期: 2008-05-13
年龄: 44
帖子: 232
声望力: 21 ![]() |
![]()
你可以在循环前,获取n2的位置设个断点,调试运行下,看看n1,n2的维数,其他地方没有出现index,只有n1和n2的应用中可能出现这个错误
__________________
工科'985'博士,(图像处理、分析及理解;模式识别;运动估计;数据分析等)定做程序、算法实现--qq:752105755 |
![]() |
![]() |