利用matlab绘制三维地形图,一个surf函数即可搞定,视角在出图之后可以拖动鼠标进行旋转
info = ncinfo('./elev.0.25-deg.nc'); %读取地形nc文件
height = ncread('./elev.0.25-deg.nc','dat a'); %读取地形高度,是一个三维数组
lat = ncread('./elev.0.25-deg.nc','lat');
lon = ncread('./elev.0.25-deg.nc','lon');
index_lat = find(lat<42 & lat>20);
index_lon = find(lon<125 & lon>95);
lat_c = lat(index_lat);lon_c = lon(index_lon);
[x,y] = meshgrid(lat_c,lon_c); %注意要将一维的经纬度meshgrid为二维数组
s1 = surf(x,y,height(index_lon,index_lat)); hold on; %画图
s1.EdgeColor = 'none';
load('E:\script tips\colorbar\OceanLakeLandSnow'); %调用自己电脑里的colorbar,也可以用matlab自带的
colormap(OceanLakeLandSnow);
colorbar
xlabel('Latitude (°)');ylabel('Longitude (°)');zlabel('altitude (m)')
set(gca,'ydir','reverse','FontSize',18,'FontName','Times New Roman','FontWeight','bold')
发现另一个有趣的画三维图的函数waterfall,图如其名,像个瀑布,暂时还没想出用途。函数使用方法和surf一致,xy要是二维的。
waterfall(x,y,height(index_lon,index_lat))