matlab绘制海表面温度、盐度等要素

一般使用nc文件。

下载文件,读取文件,绘制海表面要素图。

数据源:WOA 2018 (noaa.gov)

代码:

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!

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值