function J =Zernike_36(W,dim)
x=linspace(-1,1,dim);
y=linspace(-1,1,dim);
[x,y] = meshgrid(x,y);
% Z3=-1+2*(x.^2+y.^2);%离焦
% Z4=x.^2-y.^2;%像散,轴线0,90
% Z5=2*x.*y;%像散,轴线+-45
% Z6=-2*x+3*x.*(x.^2+y.^2);%沿X轴的三级慧差r
% Z7=-2*y+3*y.*(x.^2+y.^2);%沿Y轴的三级慧差
% Z8=1-6*(x.^2+y.^2)+6*(x.^2+y.^2).^2;%三级球差
%
% sq = (x.^2+y.^2);
% s2 = sqrt(2);
% s3 = sqrt(3);
% s5 = sqrt(5);
% s7 = sqrt(7);
%
% Z9 = 2*s2*y.*(3*x.^2-y.^2);
% Z10 = 2*s2*x.*(x.^2-3*y.^2);
% Z11 = s5*(6*sq.^2-6*sq+1);
% Z12 = s2*s5*(x.^2-y.^2).*(4*sq-3);
% Z13 = 2*s2*s5*x.*y.*(4*sq.^2-3);
% Z14 = s2*s5*(sq.^2-8*x.^2*y.^2);
% Z15 = 4*s2*s5*(x.^2-y.^2);
% Z16 = 2*s3*x.*(10*sq.^2-12*sq+3);
%
% Z17 = 2*s3*y.*(10*sq.^2-12*sq+3);
% Z18 = 2*s3*x.*(x.^2-3*y.^2).*(5*sq-4);
% Z19 = 2*s3*y.*(3*x.^2-y.^2).*(5*sq-4);
% Z20 = 2*s3*x.*(16*x.^4-20*x.^2.*sq+5*sq.^2);
% Z21 = 2*s3*y.*(16*y.^4-20*y.^2.*sq+5*sq.^2);
% Z22 = s7*(20*sq.^3-30*sq.^2+12*sq-1);
% Z23 = 2*s2*s7*x.*y.*(15*sq.^2-20*sq+6);
% Z24 = s2*s7*(x.^2-y.^2).*(15*sq.^2-20*sq+6);
% Z25 = 4*s2*s7*x.*y.*(x.^2-y.^2).*(6*sq-5);
% Z26 = s2*s7*(8*x.^4-8*x.^2.*sq+sq.^2).*(6*sq-5);
% Z27 = s2*s7*(32*x.^4-32*x.^2.*sq+6*sq.^2);
% Z28 = s2*s7*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('Z3.txt','wt');
fid4=fopen('Z4.txt','wt');
fid5=fopen('Z5.txt','wt');
fid6=fopen('Z6.txt','wt');
fid7=fopen('Z7.txt','wt');
fid8=fopen('Z8.txt','wt');
fid9=fopen('Z9.txt','wt');
fid10=fopen('Z10.txt','wt');
fid11=fopen('Z11.txt','wt');
fid12=fopen('Z12.txt','wt');
fid13=fopen('Z13.txt','wt');
fid14=fopen('Z14.txt','wt');
fid15=fopen('Z15.txt','wt');
fid16=fopen('Z16.txt','wt');
fid17=fopen('Z17.txt','wt');
fid18=fopen('Z18.txt','wt');
fid19=fopen('Z19.txt','wt');
fid20=fopen('Z20.txt','wt');
fid21=fopen('Z21.txt','wt');
fid22=fopen('Z22.txt','wt');
fid23=fopen('Z23.txt','wt');
fid24=fopen('Z24.txt','wt');
fid25=fopen('Z25.txt','wt');
fid26=fopen('Z26.txt','wt');
fid27=fopen('Z27.txt','wt');
fid28=fopen('Z28.txt','wt');
fid29=fopen('Z29.txt','wt');
fid30=fopen('Z30.txt','wt');
fid31=fopen('Z31.txt','wt');
fid32=fopen('Z32.txt','wt');
fid33=fopen('Z33.txt','wt');
fid34=fopen('Z34.txt','wt');
fid35=fopen('Z35.txt','wt');
fid36=fopen('Z36.txt','wt');
fid38=fopen('ZW.txt','wt');
for i=1:1:dim
for j=1:1:dim
if(W(i,j)~=0)
% fprintf(fid3,'%f ',Z3(i,j));
fprintf(fid4,'%f ',Z4(i,j));
fprintf(fid5,'%f ',Z5(i,j));
fprintf(fid6,'%f ',Z6(i,j));
fprintf(fid7,'%f ',Z7(i,j));
fprintf(fid8,'%f ',Z8(i,j));
fprintf(fid9,'%f ',Z9(i,j));
fprintf(fid10,'%f ',Z10(i,j));
fprintf(fid11,'%f ',Z11(i,j));
fprintf(fid12,'%f ',Z12(i,j));
fprintf(fid13,'%f ',Z13(i,j));
fprintf(fid14,'%f ',Z14(i,j));
fprintf(fid15,'%f ',Z15(i,j));
fprintf(fid16,'%f ',Z16(i,j));
fprintf(fid17,'%f ',Z17(i,j));
fprintf(fid18,'%f ',Z18(i,j));
fprintf(fid19,'%f ',Z19(i,j));
fprintf(fid20,'%f ',Z20(i,j));
fprintf(fid21,'%f ',Z21(i,j));
fprintf(fid22,'%f ',Z22(i,j));
fprintf(fid23,'%f ',Z23(i,j));
fprintf(fid24,'%f ',Z24(i,j));
fprintf(fid25,'%f ',Z25(i,j));
fprintf(fid26,'%f ',Z26(i,j));
fprintf(fid27,'%f ',Z27(i,j));
fprintf(fid28,'%f ',Z28(i,j));
fprintf(fid29,'%f ',Z29(i,j));
fprintf(fid30,'%f ',Z30(i,j));
fprintf(fid31,'%f ',Z31(i,j));
fprintf(fid32,'%f ',Z32(i,j));
fprintf(fid33,'%f ',Z33(i,j));
fprintf(fid34,'%f ',Z34(i,j));
fprintf(fid35,'%f ',Z35(i,j));
fprintf(fid36,'%f ',Z36(i,j));
fprintf(fid38,'%f ',W(i,j));
end
end
end
% fid=fopen('Z3.txt','rt');
% H1=fscanf(fid,'%f');
fid=fopen('Z4.txt','rt');
H2=fscanf(fid,'%f');
fid=fopen('Z5.txt','rt');
H3=fscanf(fid,'%f');
fid=fopen('Z6.txt','rt');
H4=fscanf(fid,'%f');
fid=fopen('Z7.txt','rt');
H5=fscanf(fid,'%f');
fid=fopen('Z8.txt','rt');
H6=fscanf(fid,'%f');
fid=fopen('Z9.txt','rt');
H7=fscanf(fid,'%f');
fid=fopen('Z10.txt','rt');
H8=fscanf(fid,'%f');
fid=fopen('Z11.txt','rt');
H9=fscanf(fid,'%f');
fid=fopen('Z12.txt','rt');
H10=fscanf(fid,'%f');
fid=fopen('Z13.txt','rt');
H11=fscanf(fid,'%f');
fid=fopen('Z14.txt','rt');
H12=fscanf(fid,'%f');
fid=fopen('Z15.txt','rt');
H13=fscanf(fid,'%f');
fid=fopen('Z16.txt','rt');
H14=fscanf(fid,'%f');
fid=fopen('Z17.txt','rt');
H15=fscanf(fid,'%f');
fid=fopen('Z18.txt','rt');
H16=fscanf(fid,'%f');
fid=fopen('Z19.txt','rt');
H17=fscanf(fid,'%f');
fid=fopen('Z20.txt','rt');
H18=fscanf(fid,'%f');
fid=fopen('Z21.txt','rt');
H19=fscanf(fid,'%f');
fid=fopen('Z22.txt','rt');
H20=fscanf(fid,'%f');
fid=fopen('Z23.txt','rt');
H21=fscanf(fid,'%f');
fid=fopen('Z24.txt','rt');
H22=fscanf(fid,'%f');
fid=fopen('Z25.txt','rt');
H23=fscanf(fid,'%f');
fid=fopen('Z26.txt','rt');
H24=fscanf(fid,'%f');
fid=fopen('Z27.txt','rt');
H25=fscanf(fid,'%f');
fid=fopen('Z28.txt','rt');
H26=fscanf(fid,'%f');
fid=fopen('Z29.txt','rt');
H27=fscanf(fid,'%f');
fid=fopen('Z30.txt','rt');
H28=fscanf(fid,'%f');
fid=fopen('Z31.txt','rt');
H29=fscanf(fid,'%f');
fid=fopen('Z32.txt','rt');
H30=fscanf(fid,'%f');
fid=fopen('Z33.txt','rt');
H31=fscanf(fid,'%f');
fid=fopen('Z34.txt','rt');
H32=fscanf(fid,'%f');
fid=fopen('Z35.txt','rt');
H33=fscanf(fid,'%f');
fid=fopen('Z36.txt','rt');
H34=fscanf(fid,'%f');
fid=fopen('ZW.txt','rt');
L=fscanf(fid,'%f');
% fclose(fid3);
fclose(fid4);
fclose(fid5);
fclose(fid6);
fclose(fid7);
fclose(fid8);
fclose(fid9);
评论12