matla仿真相干合成一些常用代码
%% 显示程序运行时间
tic
toc
%%批量保存mat文件
name=['g=' num2str(gamma) 'a=' num2str(amp*100)''];
save(name,'m1');
%%归一化颜色图
max1=max(max(I1));
I1=I1/max1;
figure(1)
imagesc(I1),axis image,axis off
colormap(jet)
colorbar('Ticks',[0,0.2,0.4,0.6,0.8,1.0]);%%颜色栏
caxis([0 1]);%颜色范围
%%设置折线图格式
figure(3)
plot(x1,L1,'--','LineWidth',2);
hold on
plot(x1,L2,'LineWidth',2);
legend('same','difference');
%%打印图片300dpi
hfig = figure(1);
figWidth = 5; % 设置图片宽度
figHeight = 5; % 设置图片高度
set(hfig,'PaperUnits','inches'); % 图片尺寸所用单位
set(hfig,'PaperPosition',[0 0 figWidth figHeight]);
fileout = ['七路相同.']; % 输出图片的文件名
print(hfig,[fileout,'tif'],'-r300','-dtiff'); % 设置图片格式、分辨率
%%取最大值脚标
[x y]=find(I1==max(max(I1)));
L1 = I1(251,:);%取某一行
%%读取bgdata数据
%%函数
function [I] = hdf5data_to_matrix(data,width,height)
% Convert the 1-D array of data into a 2-D matrix, or image.
I = zeros(height,width);
index = 1;
for i = 1:height
for j = 1:width
I(i,j) = data(index);
index = index + 1;
end
end
%%调用
filename=['21.bgData'];% % % filename =strcat('F:\6.1重做\',num2str(dbomg),'\back.bgData');
sernum=37;%%帧数
readhdf5tmp;
D21=I; %%fig
figure(1)
imagesc(I),axis image,axis off
title('far field')
colormap(jet)
%计算环大小r、性能指标J、环矩阵P
function [r,rh,re,J,Ie]=cf61(I)
[x_max,y_max]=find(I==max(max(I(:)))); %寻找光强峰值
[xsize,ysize]=size(I);
%%
%全宽
for cnt1=x_max:xsize
if (I(cnt1,y_max)-I(cnt1+1,y_max))<0 & I(cnt1,y_max)<0.5*I(x_max,y_max)
break
end
end
for cnt2=x_max:-1:1
if (I(cnt2+1,y_max)-I(cnt2,y_max))<0 & I(cnt2,y_max)<0.5*I(x_max,y_max)
break
end
end
r=ceil(1*abs(cnt2-cnt1)/2) %确定环的大小,全宽
%%
%半宽
for cnt3=x_max:xsize
if I(cnt3,y_max)<0.5*I(x_max,y_max)
break
end
end
for cnt4=x_max:-1:1
if I(cnt4,y_max)>0.5*I(x_max,y_max)
break
end
end
rh=ceil(abs(cnt3-cnt4)/2) %确定环的大小,全宽
%%
%半宽
for cnt5=x_max:xsize
if I(cnt5,y_max)<0.1353*I(x_max,y_max)
break
end
end
for cnt6=x_max:-1:1
if I(cnt6,y_max)>0.1353*I(x_max,y_max)
break
end
end
re=ceil(abs(cnt5-cnt6)/2) %确定环的大小,束腰
%%
N=xsize;
x=linspace(1,N,N);
[x,y]=meshgrid(x,x);
r0=sqrt((x-x_max(1)).^2+(y-y_max(1)).^2);
P=zeros(N,N);
%平顶光束输出矩阵的一倍衍射环,r=20
a=find(r0