Main Content


Define chunking parameters for netCDF variable



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).


collapse all

ncid = netcdf.create("","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]);

Input Arguments

collapse all

Identifier of a netCDF file, returned by netcdf.create or, 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.


Chunk size is determined by the netCDF library.

Data Types: double


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

Version History

Introduced in R2010b