Main Content

coder.PrimitiveType Class

Namespace: coder
Superclasses: coder.ArrayType

Represent set of logical, numeric, or character arrays acceptable for input specification

Description

Objects of coder.PrimitiveType specify logical, numeric, or character values that the generated code accepts. Supported types are half, double, single, int8, uint8, int16, uint16, int32, uint32, int64, uint64, char, and logical. Use objects of this class only with the -args option of the fiaccel command. Do not pass as an input to a generated MEX function.

Creation

t = coder.typeof(v) creates a coder.PrimitiveType object denoting the smallest non-constant type that contains v. v must be a MATLAB® numeric, logical or character.

t = coder.typeof(v,sz,variableDims) creates a coder.PrimitiveType object with upper bound sizes specified by sz and variable dimensions indicated in variableDims. If sz specifies Inf for a dimension, then the size of the dimension is unbounded and variable sized. When sz is [], the upper bound sizes of v 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(numericClass,sz,variableDims) creates a coder.PrimitiveType object representing values of class numericClass with upper bound sizes sz and variable dimensions indicated in variableDims. If sz specifies Inf for a dimension, then the size of the dimension is unbounded and 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.

t = coder.newtype(numericClass,sz,variableDims,Name=Value) creates a coder.PrimitiveType object with additional options specified by one or more name,-value arguments. Name is a property name and Value is the corresponding value. Specify Name as character vector or string scalar. You can specify several name-value arguments in any order as Name1=Value1,…,NameN=ValueN.

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 variable, specified as a numeric, logical, or character value.

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.

Primitive class type, specified as a string scalar or character vector.

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Option to create a coder.PrimitiveType object that can represent complex values, specified as a numeric or logical 1 (true) or 0 (false).

Option to create a coder.PrimitiveType object that can represent sparse values, specified as a numeric or logical 1 (true) or 0 (false).

Option to create a coder.PrimitiveType object that can represent GPU data values, specified as a numeric or logical 1 (true) or 0 (false).

Properties

expand all

Option to represent complex values, specified as a 0 or 1. The type must support complex data. Character arrays do not support complex data.

Option to represent sparse data, specified as a 0 or 1. The type must support sparse data. Character and half-precision data types do not support sparse data.

Option to represent the GPU input type, specified as a 0 or 1. This option requires a GPU Coder™ license. The type must support GPU data. Character and half-precision data types do not support GPU arrays.

Examples

collapse all

Use coder.typeof and specify the input variable, dimensions, and variable-size flag.

z = coder.typeof(0,[2 3 4],[1 1 0]) 
z = 
coder.PrimitiveType
   :2×:3×4 double

Create a coder.PrimitiveType object.

z = coder.typeof(0,[2 3 4],[1 1 0])

Generate a C library for a MATLAB function that has one input parameter of type z.

codegen -config:lib fcn -args {z}

Version History

Introduced in R2011a