Matlab代码求详细解释

代码如下:K = reshape(K(:,1:end-1),[ ],1)

第1个回答  2014-06-16
function dispersion_disp(path,pitch)
%display the dispersion calculated by the multipole method.
if nargin<2
pitch=1;
end
fid=fopen(path,'r');
data=fscanf(fid,'%f');
lambda=data(1:3:length(data));
neff=data(2:3:length(data));
%nimag=data(3:3:length(data));
figure;plot(lambda,neff);
%figure;plot(lambda,nimag);
fclose(fid);
wavelength=1.55e-6.*lambda/pitch;
d1=diff(neff);
w1=diff(wavelength);
d2=diff(d1./w1);
% w2=diff(w1);
c=2.99792458e8;
dispersion=-1.*wavelength(3:length(wavelength))./c.*d2./w1(2:length(w1));
figure;plot(wavelength(3:length(wavelength))*1e9,dispersion*1e6);title('wavelength vs dispersion');
xlabel('nm');ylabel('ps/km.nm');
龙 12:54:32
function dispersion_disp(path,pitch)%构建函数,两个变量,其中一个是路径
%display the dispersion calculated by the multipole method.
if nargin<2%如果输入参数的个数小于2则以下结果
pitch=1;
end
fid=fopen(path,'r');%打开路径下的数据文件
data=fscanf(fid,'%f');%读入文件数据
lambda=data(1:3:length(data));%设置lambda的值
neff=data(2:3:length(data)); %设置neff的值
%nimag=data(3:3:length(data));
figure;plot(lambda,neff);%绘图
%figure;plot(lambda,nimag);
fclose(fid);
wavelength=1.55e-6.*lambda/pitch;
d1=diff(neff);%求差值
w1=diff(wavelength);
d2=diff(d1./w1);
% w2=diff(w1);
c=2.99792458e8;
dispersion=-1.*wavelength(3:length(wavelength))./c.*d2./w1(2:length(w1));%计算dispersion
figure;plot(wavelength(3:length(wavelength))*1e9,dispersion*1e6);title('wavelength vs dispersion');%图形绘制
xlabel('nm');ylabel('ps/km.nm');