一般使用nc文件。
下载文件,读取文件,绘制海表面要素图。
代码:
clear;
clc;
source1 = 'woa18_decav_t00_04.nc'; %读取文件
ncdisp(source1); %查阅nc文件信息
boundary = [-180 180 -90 90]; %设置经纬度范围
lon = ncread(source1,'lon'); %查阅经度信息
loncount = length(lon); %查阅经度精度(有多少格点)
lat = ncread(source1,'lat'); %查阅纬度信息
latcount = length(lat); %查阅纬度精度(有多少格点)
time = ncread(source1,'time'); %查阅时间层数信息
ticount = length(time); %查阅时间层数
t = 1;
varname = 't_an'; %根据ncdisp显示的变量输入绘图
lon_scope = find(lon >= boundary(1) & lon <= boundary(2));
lat_scope = find(lat >= boundary(3) & lat <= boundary(4));
lon_number = length(lon_scope);
lat_number = length(lat_scope);
start = [lon_scope(1),lat_scope(1),1,1]; %初始位置
count = [lon_number,lat_number,ticount,1]; %读取范围
stride1 = [1,1,1,1]; %读取步长
sst1 = ncread(source1,varname,start,count,stride1); %读取温度
%sst2 = sst1-273.15; %若数据是开尔文需要转换的话
sst_plot = imrotate(sst1(:,:,t), 90); %旋转矩阵,因为matlab是列优先
SST_plot = flipud(sst_plot);
m_proj('Miller Cylindrical','lat',[boundary(3) boundary(4)],'lon',[boundary(1) boundary(2)]);
%投影并做图
lat_1 = linspace(boundary(3),boundary(4),lat_number);
lon_1 = linspace(boundary(1),boundary(2),lon_number);
[plon,plat] = meshgrid(lon_1,lat_1);
hold on
m_pcolor(plon,plat,SST_plot) %添加画的内容
m_coast('color',[0 0 0],'linewidth',1); %绘制海岸线并填充陆地
m_grid('box','fancy') %添加边框
hold on
title('SST','fontsize',15) %设置标题
colormap jet; %添加colorbar
h = colorbar('h');
set(get(h,'title'),'string','摄氏度℃');
over!