Main Content

matlab.io.hdfeos.gd.defField

Namespace: matlab.io.hdfeos.gd

Define new data field within grid

Syntax

defField(gridID,fieldname,dimlist,dtype)
defField(gridID,fieldname,dimlist,dtype,mergeCode)

Description

defField(gridID,fieldname,dimlist,dtype) defines data fields for a grid specified by gridID. The fieldname input is the name of the new field. dimlist is a cell array of geolocation dimensions and should be listed in FORTRAN-style order, that is, the fastest varying dimension should be listed first. Specify dimlist as a cell array of character vectors or a string array containing text which describes the dimensions or just a character vector or string scalar when there is only one dimension. dtype is the data type of the field.

defField(gridID,fieldname,dimlist,dtype,mergeCode) defines a data field with a specific merge code. mergeCode can be either 'nomerge' or 'automerge'. The mergeCode input defaults to 'nomerge' if not provided.

This function corresponds to the GDdeffield function in the HDF library C API, but because MATLAB® uses FORTRAN-style ordering, the dimlist parameter is reversed with respect to the C library API.

Examples

Define a single precision grid field 'Temperature' with dimensions 'XDim' and 'YDim'. Then define a single precision field 'Spectra' with dimensions 'XDim', 'YDim', and 'Bands'.

import matlab.io.hdfeos.*
gfid = gd.open('myfile.hdf','create');
xdim = 120; ydim = 200;
gridID = gd.create(gfid,'geo',xdim,ydim,[],[]);
gd.defProj(gridID,'geo',[],[],[]);
dimlist = {'XDim','YDim'};
gd.defField(gridID,'Temperature',dimlist,'single'); 
gd.defDim(gridID,'Bands',3);
dimlist = {'XDim','YDim','Bands'};
gd.defField(gridID,'Spectra',dimlist,'uint8'); 
gd.detach(gridID);
gd.close(gfid);