绘制成图如下:
代码如下:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%创建绘图的数据
ax=0;bx=1;
ay=0;by=1;
nx=100; %数据的x轴点数
ny=100; %数据的y轴点数
hx=(bx-ax)/(nx-1);
hy=(by-ay)/(ny-1);
X=ax:hx:bx;
Y=ay:hy:by;
data=zeros(ny,nx);
for ix=1:nx
for iy=1:ny
data(iy,ix)=sin(X(1,ix)+Y(1,iy)); %云图的数据
end
end
Nhang=5; %划分区域的行数
Nlie=6; %划分区域的列数
wei_shu=3; %均值保留的小数位数
figure(1)
hold on
title('区域均值云图');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wei_shu1=strcat('%.',num2str(wei_shu),'f');
nx=size(data,2);
ny=size(data,1);
hx=(bx-ax)/(nx-1);
hy=(by-ay)/(ny-1);
X=ax:hx:bx;
Y=ay:hy:by;
imagesc(X,Y,data);
axis([ax bx ay by]);
Hx=(bx-ax)/(Nlie);
Hy=(by-ay)/(Nhang);
XXC=ax:Hx:bx;
YYC=ay:Hy:by;
NNX=100;
NNY=100;
HHHX=(XXC(1,2)-XXC(1,1))/NNX;
HHHY=(YYC(1,2)-YYC(1,1))/NNY;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%区域中均值的计算
for j=1:Nhang
for i=1:Nlie
emperical_x=XXC(1,i):HHHX:XXC(1,i+1);
emperical_y=YYC(1,j):HHHY:YYC(1,j+1);
sum=0;
for iii=1:NNX
for jjj=1:NNY
sum=sum+interp2(X, Y, data,emperical_x(1,iii),emperical_y(1,jjj), 'linear')/NNX/NNY;
end
end
SUM=num2str(sum,wei_shu1);
text(XXC(1,i)+Hx/2-0.3*Hx,YYC(1,j)+Hy/2, SUM, 'FontSize', 12, 'Color', 'black', 'Rotation', 0);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for iy=1:Nhang+1
x_points=[ax,bx];
y_points=[YYC(1,iy),YYC(1,iy)];
plot(x_points,y_points,'k-');
end
for ix=1:Nlie+1
x_points=[XXC(1,ix),XXC(1,ix)];
y_points=[ay,by];
plot(x_points,y_points,'k-');
end
hold off