Picking out a specific time period from a NetCDF file?

조회 수: 5 (최근 30일)
Maya Lewis
Maya Lewis 2020년 11월 4일
편집: L Chi 2021년 6월 22일
Hi, I have a NetCDF file containing rainfall data for multiple river basins. I only need data for a particular time period (1980-2000) could some body help me pick these out? Thank you.
I have tried the below but I'm met with the error message: The logical indices in position 3 contain a true value outside of the array bounds.
rainfall = double(ncread(fname,'rainfall'));
TIME=double(ncread(fname,'time'));
TIME2 = double(TIME)/24 + datenum('1800-01-01 00:00:00');
TIME3=datestr(TIME2,0);
years=datevec(TIME3);
from_year = 1980; to_year = 2000;
baseline = years(:,1) >= from_year & years(:,1) <= to_year;
baseline_rainfall = rainfall(:, :, baseline);

채택된 답변

KSSV
KSSV 2020년 11월 4일
  1. Read the time data from netCDF file
  2. Convert them into datevec, and pick the years you want using ismember or logical indexing.
  3. Pick the data using those indices.
  댓글 수: 1
Maya Lewis
Maya Lewis 2020년 11월 4일
Thank you. Could you possibly show me an example?
thanks again

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

L Chi
L Chi 2021년 6월 22일
편집: L Chi 2021년 6월 22일
You can try this toolbox: https://github.com/HappySpring/Easy_NetCDF
The following command should solve the problem.
[ out_dim, rainfall ] = FUN_nc_varget_enhanced_region_2( fname, 'rainfall', {'time'}, {[datenum(1980,1,1) datenum(2000,12,31,23,59,59)]}, 'time' );
where {'time'}, {[datenum(1980,1,1) datenum(2000,12,31,23,59,59)]} set the limit for time
and the 'time' follows the above codes indicates that the variable named 'time' should be treated as time.

카테고리

Help CenterFile Exchange에서 NetCDF에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by