zheng720 发表于 2008-4-7 13:01

Subscript indices must either be real positive integers or logicals 出错求助

c=299792458;%velocity in vacuum
a=xlsread('b.xls'); wavelength=a(57:136,1)*10^-9;
wavelength_delta=0.005*10^-9;
f=c./wavelength;
gd=a(57:136,2)*10^-12;
N=length(gd);

phase=zeros(N,1);
for n=1:N/2-1
    phase(N/2-n)=phase(N/2-n-1)-2*pi*c*wavelength_delta*sum(1./wavelength(N/2-n).^2.*gd(N/2-n));
end
for n=1:N/2
    phase(N/2+n)=-phase(N/2)-2*pi*c*wavelength_delta*sum(1./wavelength(N/2:N/2+n).^2.*gd(N/2:N/2+n));
end
F=polyfit(f,phase,2);
phase_fit=F(1)*f.^2+F(2)*f+F(3);%拟合

figure(1)
plot(wavelength,phase,'r')
hold on
plot(wavelength,phase_fit,'b')
出错提示:??? Subscript indices must either be real positive integers or logicals.
不知道为什么呀,我想实现的是:最后得到的phase为一个N*1的矩阵,其中画出来的phase结果应该是一条平滑的曲线。主要是需要处理中间的当n=N/2时的phase值的问题,谢谢了,急需!万分感谢

[ 本帖最后由 eight 于 2008-4-7 16:16 编辑 ]

eight 发表于 2008-4-7 16:17

原帖由 zheng720 于 2008-4-7 13:01 发表 http://www.chinavib.com/forum/images/common/back.gif
c=299792458;%velocity in vacuum
a=xlsread('b.xls'); wavelength=a(57:136,1)*10^-9;
wavelength_delta=0.005*10^-9;
f=c./wavelength;
gd=a(57:136,2)*10^-12;
N=length(gd);

phase=zeros(N,1);
fo ... http://www.chinavib.com/forum/thread-46001-1-1.html 2楼

zheng720 发表于 2008-4-7 16:57

已搞定了
页: [1]
查看完整版本: Subscript indices must either be real positive integers or logicals 出错求助