netcdf.defVlen
Description
Examples
Create and Write NC_VLEN Type
Define a new NC_VLEN
type in a new NetCDF-4 file. Then, create and write a variable of this type. An NC_VLEN
type corresponds to a cell array in MATLAB®.
Create a NetCDF-4 file named myfile.nc
.
source = "myfile.nc"; cmode = "NETCDF4"; ncid = netcdf.create(source,cmode);
Define a new NC_VLEN
type with the MY_VARIABLE_LENGTH_SAMPLE
type name and NC_FLOAT
base type.
typeName = "MY_VARIABLE_LENGTH_SAMPLE"; baseType = "NC_FLOAT"; typeid = netcdf.defVlen(ncid,typeName,baseType);
Create a new TIME
dimension with the length 3
in the NetCDF file.
dimname = "TIME";
dimlen = 3;
dimid = netcdf.defDim(ncid,dimname,dimlen);
Create a new variable named samples
of the NC_VLEN
type and with the TIME
dimension.
varname = "samples";
varid = netcdf.defVar(ncid,varname,typeid,dimid);
Write the data to the NetCDF variable. The data is a cell array that contains arrays of single
values. The NC_FLOAT
NetCDF data type corresponds to the single
data type in MATLAB.
data = {single([0.1,0.2]),single([2.333,7.94,0.5,0]),single(4.2)}; netcdf.putVar(ncid,varid,data)
Close the NetCDF file.
netcdf.close(ncid)
Display the contents of the NetCDF-4 file. The ncdisp
function lists the new NC_VLEN
type in the User-Defined Types
section and represents it by its base data type (single
) inside curly braces. The Datatype
of the new samples
variable shows the name of the NC_VLEN
type, MY_VARIABLE_LENGTH_SAMPLE
.
ncdisp(source)
Source: /tmp/Bdoc23a_2213998_1184146/tp56fdf280/matlab-ex80861297/myfile.nc Format: netcdf4 User-Defined Types: MY_VARIABLE_LENGTH_SAMPLE: {single} Dimensions: TIME = 3 Variables: samples Size: 3x1 Dimensions: TIME Datatype: MY_VARIABLE_LENGTH_SAMPLE
Input Arguments
ncid
— File identifier
integer
File identifier of an open NetCDF file or OPeNDAP NetCDF data source, specified as an integer.
You can retrieve this identifier by using the netcdf.open
function.
Data Types: double
typeName
— Type name
string scalar | character vector
Type name for a new NC_VLEN
type, specified as a string scalar or
character vector.
Data Types: string
| char
baseType
— Base type of new NC_VLEN
type
string scalar | character vector | integer
Base type of the new NC_VLEN
type, specified as a string scalar,
character vector (such as NC_DOUBLE
), or as an integer that is the
equivalent numeric type identifier. You can use the netcdf.getConstant
function to retrieve the numeric type identifier. The
baseType
value represents the type of the elements inside the
user-defined NC_VLEN
type.
Data Types: string
| char
| double
Output Arguments
typeID
— Data type identifier
integer
Data type identifier for a user-defined NC_VLEN
type, returned as
an integer.
Version History
Introduced in R2022a
See Also
netcdf.inqVlen
| netcdf.inqUserType
| netcdf.create
| netcdf.defDim
| netcdf.defVar
| netcdf.putVar
| netcdf.close
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)