How to Extract NetCDF Temperature data using MATLAB
3 ビュー (過去 30 日間)
古いコメントを表示
Hi there,
Hope to be fine and everything goes well.
I have an nc file named cru_ts4.06.2001.2010.tmx.dat.nc.gz, that has been downloaded from CRU website (https://crudata.uea.ac.uk/cru/data/hrg/cru_ts_4.06/cruts.2205201912.v4.06/tmx/ ).
I wrote the attached MATLAB code to extract Tmax data, but I have some problems extracting Tmax for a specific station i.e. for a given Lat & ong. May I help me to debug the problem?
Any help would be appreciated
clear all ; clc;
%%% This Program transfer data from netcdf file to excel sheet
%% Step 1: Specify one station to retrieve data : specify Longitude & Latitude
% Size: 720x360x120 >> Dimensions: lon,lat,time
display ('Latitude for Kerman Station= 30.15')
% lat=input ('Enter your Latitude=')
lat= 30.15
display ('Longitude for Kerman Station=56.57')
% lon=input ('Enter your Longitude =')
lon=56.57
%% Step 2: Display all variables in nc file : ncdisplay
ncfile='E:\HiTec-Propsals\6th Prop_Non Sta_22 04 1401\Docs_05 04 1401\Yazd_Water Authority_18 08\MATLAB_NC Data\cru_ts4.06.2001.2010.tmx.dat.nc' ;
Tmax = 'cru_ts4.06.2001.2010.tmx.dat.nc';
whos Tmax
ncdisp(Tmax) ;
fileName=Tmax;
%% ncinfo
info=ncinfo(Tmax);
nVar=size(info.Variables, 2)
disp('Variable names are:')
unitsTime = info.Variables(3).Attributes(2);
unitsTmax = info.Variables(4).Attributes(2).Value;
for ii=1:nVar
disp(info.Variables(ii).Name);
end
%% Step 3: Load netcdf variables from nc file : ncread : {'lon';'lat';'time';'tmx';'stn'}
Tmax_Data = ncread(fileName, 'tmx');
LON = double(ncread(fileName,'lon') );
LAT = double( ncread(fileName,'lat') ) ;
Time = ncread(fileName,'time');
Station = ncread(fileName,'stn');
Time=double(Time);
%% Step 4: Find index of Longitude & Latitude in the dimension of array
% LGG=find (lon==LG)
% LTT=find (lat==LT)
%% Example
% data=getValue(lat, lon, LAT, LON, Tmax_Data);
Tmax_data2=getValue( LAT, LON,Time, [221 441 1], [271 501 1], Tmax_Data);
%% Making the Grid
[GLat,GLon,GF] = meshgrid(lat,lon,Time);
%% Extract Location Lat & Lon
% location_lat = knnsearch(LAT,18.5);
% location_lon = knnsearch(LON,102.5);
0 件のコメント
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で NetCDF についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!