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)
Show the datatype and dimensions of the samples
variable using the ncinfo
function. The Variables
field of the info
structure shows the datatype that you defined and the Dimensions
subfield shows the dimension that you defined.
info = ncinfo(source); info.Variables
ans = struct with fields:
Name: 'samples'
Dimensions: [1x1 struct]
Size: 3
Datatype: 'MY_VARIABLE_LENGTH_SAMPLE'
Attributes: []
ChunkSize: []
FillValue: {[]}
DeflateLevel: []
Shuffle: 0
info.Variables.Dimensions
ans = struct with fields:
Name: 'TIME'
Length: 3
Unlimited: 0
Input Arguments
ncid
— Identifier of netCDF source
nonnegative integer scalar
Identifier of a netCDF source, specified as a nonnegative integer scalar. The netCDF source can be a netCDF file or a netCDF group.
Data Types: double
| single
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
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)