Clear Filters
Clear Filters

Error sending data to .xlsx (NetCDF)

1 view (last 30 days)
I have the CHIRPS data plus these scripts and at the time the data is sent to the .xlsx it has errors in the dates and the precipitation data is blank.
the biggest problem is the years, months and days
Does anyone have an idea to solve?
download link:
https://data.chc.ucsb.edu/products/CHIRPS-2.0/global_daily/netcdf/p25/
the functions used are attached (get_and_save_ncf_data.m license.txt testfun.m natsortfiles_test.m natsort.m natsortfiles.m natsortfiles_doc.m)
%% Long and Lat
LG=[-48.375]; % longitude
LT=[-1.125]; % latitude
%% main code
fileDir = pwd; % current directory (or specify which one is the working directory)
S = dir(fullfile(fileDir,'*.nc')); % get list of nc files in directory
S = natsortfiles(S); % sort file names into natural order , see :
%(https://fr.mathworks.com/matlabcentral/fileexchange/47434-natural-order-filename-sort)
for k = 1:length(S)
filename = S(k).name % to actually show filenames are sorted (see command window)
sheet = 1; % for excel file output, either on first sheet or increment sheet number if needed
filename_out = [filename(1:length(filename)-3) '.xlsx']; % replace nc extension with xlsx (or whatever you want)
get_and_save_ncf_data(fullfile(fileDir, filename),LG,LT,fullfile(fileDir, filename_out),sheet);
end

Accepted Answer

Mathieu NOE
Mathieu NOE on 21 Dec 2022
hello Augusto
just correct this line in your function "get_and_save_ncf_data.m":
those nc files are daily data (time increment = day not hour) and there are referred to 1980 not 1900
% AA=time/24+datenum('1900-01-01 0:0:0'); % time in hours
AA=time+datenum('1980-01-01 0:0:0'); % time in days, reference is 1980 not 1900

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!