Extracting time series for each lat/long from a netCDF
Show older comments
Hello all,
I'm trying to extract a time series text file for each lat/long in a netCDF. Specifically, I would like to extract a daily precipitation time series for each lat/long combination in the netCDF.
Here is what I have so far:
pr=ncread('Extraction_pr.nc','pr');%Extract precip. from the netCDF
long_num=78; %number of longitudes
lat_num=61; %number of latitudes
%extract all latitude,longitude weather combinations
for i = 1:long_num
for j = 1:lat_num
lat(i,j,:)=pr(i,j,:);
dlmwrite(['lat',num2str(j),'.txt'],lat(i,j,:))
end
end
%extract all longitude,latitude weather combinations
for x = 1:lat_num% number of latitudes
for y = 1:long_num % number of longitudes
long(y,x,:)=pr(y,x,:);
dlmwrite(['long',num2str(y),'.txt'],long(y,x,:))
end
end
txtFiles = dir('*.txt');
filename = cell(length(txtFiles),1); % preallocate
data = cell(length(txtFiles),1); % preallocate
for k = 1:length(txtFiles)
filename{k} = txtFiles(k).name;
data{k} = dlmread(filename{k});
data_trans{k}= transpose(data{k});
dlmwrite(filename{k},data_trans{k},'');
end
%%%%%%%%%%%%%
Of course this isn't working because I'm not getting repeating lat or long numbers like (X,Y), (X,Y+1), (X,Y+2). Any idea?
I'm fairly new to Matlab so any help would be appreciated. Thanks!
1 Comment
Sohrab Kolsoomi
on 4 Dec 2017
hi You can watch video in youtube for calculating Grid number in: AgriMetSoft and free use Netcdf-Extractor V1.1 for calculate his
Answers (0)
Categories
Find more on NetCDF in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!