在绘制海温图的时候温度出现温度数据问题,应该画出的图是
但我画出来
代码在这里
%读取全部海温资料,用select函数挑选经纬度和时间
ncdisp('./sst.mnmean.nc');
sst=ncread('./sst.mnmean.nc',"sst");
lon=ncread('./sst.mnmean.nc',"lon");
lat=ncread('./sst.mnmean.nc',"lat");
time=ncread('./sst.mnmean.nc',"time");
sst_series = select( sst, 0, 88, 179, 88,time,lon,lat,[1950,2,1],[2021,2,1]);
%计算每年海温均值
for j=1:1:71
for i=1:1:12
if i==9
m_sst(:,:,j)=mean(sst_series(:,:,(j-1)*12+i:(j-1)*12+i+3),3);
end
end
end
%取出逐年平均数据,去季节化
ncdisp('./sst.mon.ltm.nc');
sst_mean=ncread('./sst.mon.ltm.nc',"sst");
lon_mean=ncread('./sst.mon.ltm.nc',"lon");
loncount = length(lon_mean);
lat_mean=ncread('./sst.mon.ltm.nc',"lat");
latcount = length(lat_mean);
time_mean=ncread('./sst.mon.ltm.nc',"time");
ticount = length(time_mean);
sst_sta=(sst_mean(:,:,1)+sst_mean(:,:,11)+sst_mean(:,:,12))/3;
sst_d=m_sst(96:96+25,43:43+4,:)-sst_sta(96:96+25,43:43+4);
%判断El Nino&La Nina year
e=0;l=0;
for j=1:1:71
if mean(sst_d(:,:,j),'all')>0.5
e=e+1;
el(:,:,e)=m_sst(:,:,j);
elseif mean(sst_d(:,:,j),'all')<0.5
l=l+1;
la(:,:,l)=m_sst(:,:,j);
end
end
%绘图
boundary = [0 358 -88 88]; %设置经纬度范围
varname = 'sst'; %根据ncdisp显示的变量输入绘图
lon_scope = find(lon_mean >= boundary(1) & lon_mean <= boundary(2));
lat_scope = find(lat_mean >= boundary(3) & lat_mean <= boundary(4));
lon_number = length(lon_scope);
lat_number = length(lat_scope);
start = [lon_scope(1),lat_scope(1),1]; %初始位置
count = [lon_number,lat_number,ticount]; %读取范围
stride1 = [1,1,1]; %读取步长
sst_plot = imrotate(sst_sta, 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') %添加边框
%m_contourf(lon_1,lat_1,SST_plot,'linewidth',0.5);%绘制等温线
hold on
title('SST','fontsize',15) %设置标题
colormap jet; %添加colorbar
h = colorbar('h');
set(get(h,'title'),'string','摄氏度℃');
看那个SST_plot数据也不是两种温度啊
“该回答引用ChatGPT”
可以采纳下面方法,请测试代码的可用性:
有用还望采纳,谢谢!
% Load the data
load data.mat
% Plot the sea surface temperature
figure
pcolor(lon,lat,SST);
shading flat
colorbar
caxis([10 30]) % Set color axis limits
xlabel('Longitude')
ylabel('Latitude')
title('Sea Surface Temperature')
% Add coastlines
hold on
plot(coast_lon, coast_lat, 'k')
hold off
其中,lon 和 lat 是经纬度网格,SST 是海温数据,coast_lon 和 coast_lat 是海岸线的经纬度。
旁观学习一下!