matlab批量读取nc文件

2022-04-08 07:50:13   文档大全网     [ 字体: ] [ 阅读: ]

#文档大全网# 导语】以下是®文档大全网的小编为您整理的《matlab批量读取nc文件》,欢迎阅读!
批量,读取,文件,matlab
读取单个nc文件的方法: clc,clear;

ncid = netcdf.open('D:\precip.mon.1981-2010.ltm.nc','NOWRITE'); %打开nc文件 ncdisp('precip.mon.1981-2010.ltm.nc'); %在命令窗中显示nc文件的变量

PrecipData = ncread('precip.mon.1981-2010.ltm.nc','precip'); %读入变量precip TimeData = ncread('precip.mon.1981-2010.ltm.nc','time'); %读入变量time LonData = ncread('precip.mon.1981-2010.ltm.nc','lon'); %读入变量lon LatData = ncread('precip.mon.1981-2010.ltm.nc','lat'); %读入变量lat

Valid_yr_countData = ncread('precip.mon.1981-2010.ltm.nc','valid_yr_count'); %读入变量validprecip_yr_count

ClimatologyData = ncread('precip.mon.1981-2010.ltm.nc','climatology_bounds'); %读入变量climato

[X, Y] = meshgrid(LatData,LonData);

contourf(Y-180.0,X,PrecipData(:,:,9)); %9月份等值面图 shading flat; %去掉等值线

colorbar('SouthOutside','Position',[0.142,0.03,0.75,0.04]); %添加颜色条 [左右,上下,长,宽]

load coast %加载全球海岸线,但是不显示出来

geoshow(lat,long); %显示出海岸线,latlongcoast的属性 hold on;

set(gca,'LineWidth',1,'FontSize',10,'Ylim',[-90,90],'Xlim',[-180,180],'Position',[0.142,0.09,0.75 ,'XTick',[-180:60:180],'XTicklabel',{'-180W','-120W','-60W','0','60E','120E','180E'}...

,'YTick',[-90:30:90],'YTicklabel',{'-90S','-60S','-30S','0','30N','60N','90N'}; %添加经纬度hold off;

netcdf.close(ncid); %关闭nc文件

批量读取nc文件的方法: clc; %清屏 clear; %清空

datadir='D:\data\降水数据\CPC Unified Gauge-Based Analysis of Daily Precipitation over CONUS\'; %所在的文件夹

filelist=dir([datadir,'*.nc']); %指定批量数据的类型

a=filelist(1).name; %查看你要读取的文件的编号。filelist(1).namewindow下为第一个标号数据 b=filelist(2).name; %查看你要读取的文件的编号。filelist(2).namewindow下为第二个标号数据 k=length(filelist); for s=1:k

filename=[datadir,filelist(s).name]; ncid=netcdf.open(filename,'NC_NOWRITE');

ncdisp('D:\data\降水数据\CPC Unified Gauge-Based Analysis of Daily Precipitation over


CONUS\precip.V1.0.1948.nc'); %在命令窗中显示nc文件的变量

%任意取其中一个来看数据中所包含的变量特征,以为下面读取数据变量做铺垫

% ncid = netcdf.open('D:\data\降水数据\CPC Unified Gauge-Based Analysis of Daily PrecipitatioCONUS\precip.V1.0.1948.nc','NOWRITE'); %打开nc文件

% ncdisp('D:\data\降水数据\CPC Unified Gauge-Based Analysis of Daily Precipitation over CONUS\precip.V1.0.1948.nc'); %在命令窗中显示nc文件的变量

PrecipData = ncread(filename,'precip'); %读入变量precip TimeData = ncread(filename,'time'); %读入变量time LonData = ncread(filename,'lon'); %读入变量lon LatData = ncread(filename,'lat'); %读入变量lat netcdf.close(ncid); % 关闭文件 end;




本文来源:https://www.wddqxz.cn/d2bd57f987254b35eefdc8d376eeaeaad1f3168a.html

相关推荐