Create variable in NetCDF file




nccreate(filename,varname) creates a scalar double variable named varname in the NetCDF file filename. If filename does not exist, nccreate creates the file using the netcdf4_classic format. To create a nonscalar variable, use the Dimensions argument.

nccreate(filename,varname,Name,Value) creates a variable named varname with additional options specified by one or more Name,Value pair arguments.

Input Arguments


Text string specifying a NetCDF file, or the name you want to assign to a new NetCDF file.


Text string specifying the name you want to assign to a variable in a NetCDF file.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.


Cell array specifying dimensions for the variable in the NetCDF file. The cell array lists the dimension name as a string followed by its numerical length: {dname1,dlength1,dname2,dlength2, ...}. If a dimension exists, specifying its length is optional. Use Inf to specify an unlimited dimension.

All formats other than netcdf4 format files can have only one unlimited dimension per file and it has to be the last in the list specified. A netcdf4 format file can have any number of unlimited dimensions in any order.

A single-dimension variable is always treated as a column vector.


Text string specifying a MATLAB® data type. When nccreate creates the variable in the NetCDF file, it uses a corresponding NetCDF datatype. The following table describes how MATLAB datatypes map to NetCDF datatypes.

MATLAB Data TypeCorresponding NetCDF Variable Type

* These data types are only available when the file is a netcdf4 format file.


Text string specifying the type of NetCDF file you want to create.

Format StringDescription
classicNetCDF 3
64bitNetCDF 3, with 64-bit offsets
netcdf4_classicNetCDF 4 classic model
netcdf4NetCDF 4 model (Use this to enable group hierarchy)

If varname specifies a group (e.g.,'/grid3/temperature'), nccreate sets the value of format to 'netcdf4'.

Default: netcdf4_classic


A scalar specifying the value to use for missing values. To disable fill values, set FillValue to the text string 'disable'. (Available for netcdf4 or netcdf4_classic formats only.)

Default: Value specified by the NetCDF library


Vector specifying the size of the chunk along each dimension, [num_rows,num_cols,..., num_ndims]. (Available for netcdf4 or netcdf4_classic formats only.)

Default: Set by the NetCDF library


Numeric value between 0 (least) and 9 (most) specifying the compression setting for the deflate filter, or the text string disable. (Available for netcdf4 or netcdf4_classic formats only.)

Default: Disabled


Boolean flag to turn on the shuffle filter. (Available for netcdf4 or netcdf4_classic formats only.)

Default: False


Create a new 2–D variable in a classic format file. Write data to this variable

          'Dimensions',{'r' 200 'c' 200},...
 ncwrite('','peaks', peaks(200));
Was this topic helpful?