matlab剖面图_海洋要素如温盐等

存一下代码

clear;
clc;

ncfile = 'woa18_decav_s00_04.nc';
varname = 's_an';

lonRange = [105 136];
latRange = [ 3 45];
target_lon = 135;
target_lat = 20;

lon = ncread( ncfile, 'lon' ); % longitude
lat = ncread( ncfile, 'lat' ); % latitude
depth = ncread( ncfile, 'depth' ); % depth
tg = ncread( ncfile, 'time' ); % time

% (a) for longitude, find the nearest zonal location
i_inx = find( lon >= lonRange(1) & ...
              lon <= lonRange(end) );

% (b) for latitude 
[tmp, j_inx] = min( abs(lat - target_lat) );
% (c) for depth, take all depth levels 
z_inx = 1:length(depth);

nx = length( i_inx ); % longitude
ny = length( j_inx ); % laitude 
nz = length( z_inx ); % depth

xx = lon(i_inx);
yy = depth;

% Define start vector (where to start your read/write)
start = [i_inx(1) j_inx(1) z_inx(1) 1];

% Define count vector (how many points to read)
count = [nx ny nz 1];

% Read data
salt = ncread( ncfile , ... % Source, i.e. hycom.nc in this case
varname, ... % Varialbe, "salt" in this case
start , ... % The Index of Start Point along each Dimension
count ); % How many points to read along each Dimension
salt = squeeze(salt)';

% plot 
pcolor( xx, yy, salt );
shading flat; 
colormap( jet );
caxis([33.5 35.5]); colorbar
set( gca, 'FontSize' , 18 , ...
'FontName' , 'Helvetica', ...
'TickDir' , 'Out' , ...
'xMinorTick', 'On' , ...
'yMinorTick', 'On' , ...
'TickLength', [0.02 0.03], ...
'Box' , 'On' , ...
'Layer' , 'Top' , ...
'yDir' , 'reverse' );
title( sprintf('%s (%d %s N)', 'salinity', target_lat, char(176)), ...
'FontSize', 20 , ...
'FontName', 'HelVetica' ); 
xlabel( 'Longitude (\circE)', ...
'FontSize', 20 , ...
'FontName', 'HelVetica'); 
ylabel( 'Depth (m)' , ...
'FontSize', 20 , ...
'FontName', 'HelVetica'); 

  • 2
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值