Main Content

netcdf.defVarChunking

Define chunking behavior for netCDF variable

Description

example

netcdf.defVarChunking(ncid,varid,storage,chunkSizes) sets the chunk settings for the variable specified by varid. Chunking is a technique to improve performance. storage specifies the type of chunking to use and chunkSizes specifies the extents of the chunk size. You must specify the chunk size used with a variable after creating the variable but before you write data to the variable.

You cannot specify the chunk size for variables in a netCDF file created with the netCDF-3 mode (CLASSIC_MODEL).

Examples

collapse all

ncid = netcdf.create("myfile.nc","NETCDF4");
latdimid = netcdf.defDim(ncid,"lat",1800);
londimid = netcdf.defDim(ncid,"col",3600);
varid = netcdf.defVar(ncid,"earthgrid","double",[latdimid londimid]);
netcdf.defVarChunking(ncid,varid,"CHUNKED",[180 360]);
netcdf.close(ncid);

Input Arguments

collapse all

Identifier of a netCDF file, returned by netcdf.create or netcdf.open, or of a netCDF group, returned by netcdf.defGrp, specified as a nonnegative integer scalar.

Data Types: double

Identifier of netCDF variable, returned by netcdf.defVar, specified as a nonnegative integer scalar.

Data Types: double

Storage type of a netCDF variable, specified as a character vector or a string scalar. If set to "CHUNKED", netCDF breaks the variable into chunks when writing into the file. If set to "CONTIGUOUS", netCDF does not break the data into chunks.

Data Types: char | string

Dimensions of the chunk, specified as a positive integer array. The order of dimensions in chunkSizes is reversed relative to what would be in the C API, because MATLAB® uses FORTRAN-style ordering.

If storage is "CONTIGUOUS", you can omit chunkSizes.

Note

Chunk size is determined by the netCDF library.

Data Types: double

Tips

  • This function corresponds to the nc_def_var_chunking function in the netCDF library C API.

Version History

Introduced in R2010b