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 1.1 1.2 1 0.9 0.7 0.5 0.6 0.3 0.6 0.4 0.6 1 1 0.6 0.9 1 0.7;
0.3 0.5 0.8 1.1 1.1 1 0.8 0.7 0.7 0.4 0.5 0.4 0.4 0.5 0.4 1.1 1.3 0.7 1 0.7 0.6;
0.3 0.5 0.9 1.1 1 0.7 0.7 0.4 0.6 0.4 0.4 0.3 0.5 0.5 0.3 0.9 1.2 0.8 1 0.8 0.4;
0.2 0.3 0.6 0.9 0.8 0.8 0.6 0.3 0.4 0.5 0.4 0.5 0.4 0.2 0.5 0.5 1.3 0.6 1 0.9 0.3;
0.2 0.3 0.3 0.7 0.6 0.6 0.4 0.2 0.3 0.5 0.8 0.8 0.3 0.2 0.2 0.8 1.3 0.9 0.8 0.8 0.4;
0.2 0.3 0.3 0.6 0.3 0.4 0.3 0.2 0.2 0.3 0.6 0.4 0.3 0.2 0.4 0.3 0.8 0.6 0.7 0.4 0.4;
0.2 0.3 0.4 0.4 0.2 0.2 0.2 0.3 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.5 0.7 0.4 0.4 0.3 0.3;
0.2 0.2 0.3 0.2 0.2 0.3 0.2 0.2 0.2 0.2 0.2 0.1 0.2 0.4 0.3 0.6 0.5 0.3 0.3 0.3 0.2;
0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.4 0.7 0.4 0.2 0.4 0.5 0.5];
%未插值直接画图
figure(1) %创建图形窗口1,并激活
surf(x,y,z);
shading flat %用shading flat命令,使曲面变的光滑
title('未插值地形图')
xlabel('横坐标')
ylabel('纵坐标')
zlabel('高度')
%三次插值后画图
%画地形图
figure(2)
xi=0:0.05:20;
yi=20:-0.05:0;
zi=interp2(x,y,z,xi',yi,'cubic'); %'cubic'三次插值
surfc(xi,yi,zi); %底面带等高线
shading flat
title('插值后地形图')
xlabel('横坐标')
ylabel('纵坐标')
zlabel('高度')
%画立体等高线图
figure(3)
contour3(xi,yi,zi);
title('立体等高线图')
xlabel('横坐标')
ylabel('纵坐标')
zlabel('高度')
%画等高线图
figure(4)
[c,h]=contour(xi,yi,zi);
clabel(c,h); %用于为2维等高线添加标签
colormap cool %冷色调
title('平面等高线图')
xlabel('横坐标')
ylabel('纵坐标')
ge