Main Content

coder.StructType class

Package: coder
Superclasses: coder.ArrayType

Represent set of MATLAB structure arrays acceptable for input specification

Description

Objects of coder.StructType specify the structure arrays that the generated code should accept. Use objects of this class only with the -args option of the codegen command. Do not pass as an input to a generated MEX function.

Creation

t = coder.typeof(structV) creates a coder.StructType object for a structure with the same fields as the scalar structure struct_v.

t = coder.typeof(structV,sz,variableDims) creates a coder.StructType with upper bound sizes specified by sz and variable dimensions indicated by variableDims. If sz specifies Inf for a dimension, then the size of the dimension unbounded and variable size. When sz is [], the upper bound sizes of structV remain unchanged. If you do not specify the variableDims, the bounded dimensions of the type are fixed. When variableDims is a scalar, this function applies this value to the bounded dimensions that are not 1 or 0, which are fixed.

t = coder.newtype('struct',structV,sz,variableDims) creates a coder.StructType object for an array of structures with the same fields as the scalar structure structV and upper bound size sz and variable dimensions indicated in variableDims. If sz specifies Inf for a dimension, then the size of the dimension is assumed to be unbounded and the dimension is assumed to be variable sized. If you do not specify the variableDims, the bounded dimensions of the type are fixed. When variableDims is a scalar, this function applies this value to the bounded dimensions that are not 1 or 0, which are fixed.

Note

You can create and edit coder.Type objects interactively by using the Coder Type Editor. See Create and Edit Input Types by Using the Coder Type Editor.

Input Arguments

expand all

Input structure variable that specifies the fields in a new structure type, specified as a scalar structure.

Size of type object dimensions, specified as a vector of integers.

Option to specify whether each dimension has a variable size, specified as a boolean vector. If you specify an element of this vector as 1, the corresponding dimension has a variable size. Otherwise, the dimension has a fixed size.

Properties

expand all

The run-time memory alignment of structures of this type in bytes.

If you have an Embedded Coder® license and use code replacement libraries (CRLs), you can align data objects that are specified as inputs to a replacement function to a specified boundary. Use this capability to take advantage of target-specific function implementations that require data to be aligned. By default, the class does not align the structure to a specific boundary, which means that CRL functions that require alignment do not match the default structure.

Value class name, returned as a string scalar.

Indication of whether structure is defined externally, returned as a 1 or 0. A value of 1 indicates that the structure is defined externally. A value of 0 indicates that the structure is defined internally.

Types of fields in the structure, specified as a structure.

External header file name, returned as a nonempty character vector or string scalar. If the structure type is externally defined, name of the header file that contains the external definition of the structure, for example, "mystruct.h". Specify the path to the file using the codegen -I option or the Additional include directories parameter in the Custom Code tab of the MATLAB® Coder™ project settings.

By default, the generated code contains #include statements for custom header files after the standard header files. If a standard header file refers to the custom structure type, then the compilation fails. By specifying the HeaderFile property, MATLAB Coder includes the header file in the required location.

Upper bound of type object, specified as a vector of integer or scalar integer.

Option to specify whether each dimension of the array has a fixed or variable size. A value of 1 indicates that the corresponding element has a variable size. A value of 0 indicates that the corresponding element has a fixed size.

Examples

collapse all

This example shows how to create a type for a structure with a variable-size field.

Create a type object by using coder.typeof.

x.a = coder.typeof(0,[3 5],1);
x.b = magic(3);
t = coder.typeof(x)
t = 
coder.StructType
   1×1 struct
      a: :3×:5 double
      b: 3×3 double

Create Externally Defined Structure Type

Create an externally defined structure type.

S.a = coder.typeof(double(0));
S.b = coder.typeof(single(0));
T = coder.typeof(S);
T = coder.cstructname(T,'mytype','extern',HeaderFile='myheader.h');

View the types of the structure fields.

T.Fields
ans = struct with fields:
    a: [1x1 coder.PrimitiveType]
    b: [1x1 coder.PrimitiveType]

Create a structure type.

ta = coder.newtype('int8',[1 1]);
tb = coder.newtype('double',[1 2],[1 1]);
z = coder.newtype('struct',struct('a',ta,'b',tb))
coder.StructType
   1x1 struct
      a: 1x1 int8 
      b: :1x:2 double  

Generate a C library for a MATLAB function fcn.m that has one input parameter of this type.

codegen -config:lib fcn -args {z}

Version History

Introduced in R2011a