How to skip rows when loading data from a netcdf file
1 view (last 30 days)
Show older comments
Celine Boulenger
on 3 Oct 2015
Commented: Celine Boulenger
on 3 Oct 2015
Hi, I am reading temperature data from a netcdf file that is a (720x360x744) matrix (it depends on longitude, latitude and time). For the latitude and longitude I only use one row depending on which city I am looking at. The temperature is measured several times a day for one month but I only want to get one measure per day. Is there a way for me to skip some rows in the last column? I want only every 24 rows, I want row 25,49,73 etc. not the ones in between.
My code so far is :
[varname, xtype, varDimIDs, varAtts] = netcdf.inqVar(Ncid111,3);
varid = netcdf.inqVarID(Ncid111,varname);
airtemp = netcdf.getVar(Ncid111,varid');
mydata=airtemp(220,114,1:744)
This gives me the whole TIME column (measures 1 through 744) but I only want every 24th measure.
Thank you for your help!!
0 Comments
Accepted Answer
Kelly Kearney
on 3 Oct 2015
Take a look at the start, count, and stride inputs that are associated with most netcdf methods, including getVar. For example,
mydata = netcdf.getVar(Ncid111, varid, [220 114 1], [1 1 Inf], [1 1 24]);
What version of Matlab are you running? If it's relatively recent, you can simplify things by using ncread:
mydata = ncread('file.nc', varname, [220 114 1], [1 1 Inf], [1 1 24]);
More Answers (0)
See Also
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!