Quantcast

Documentation Center

  • Trial Software
  • Product Updates

coder.typeof

Package: coder

Convert MATLAB value into its canonical type

Syntax

t=coder.typeof(v)
t=coder.typeof(v, sz, variable_dims)
t=coder.typeof(t)

Description

t=coder.typeof(v) creates a coder.Type object denoting the smallest nonconstant type that contains v. v must be a MATLAB® numeric, logical, char, enumeration or fixed-point array, or a struct constructed from the preceding types. Use coder.typeof to specify only input parameter types. For example, use it with the fiaccel function -args option. Do not use it in MATLAB code from which you intend to generate a MEX function.

t=coder.typeof(v, sz, variable_dims) returns a modified copy of t=coder.typeof(v) with (upper bound) size specified by sz and variable dimensions variable_dims. If sz specifies inf for a dimension, then the size of the dimension is unbounded and the dimension is variable size. When sz is [], the (upper bound) sizes of v remain unchanged. If you do not specify the variable_dims input parameter, the bounded dimensions of the type are fixed. When variable_dims is a scalar, it is applied to bounded dimensions or dimensions that are 1 or 0, which are fixed.

t=coder.typeof(t), where t is a coder.Type object, returns t itself.

Input Arguments

sz

Size vector specifying each dimension of type object

t

coder.Type object

v

MATLAB expression that describes the set of values represented by this type.

v must be a MATLAB numeric, logical, char, enumeration or fixed-point array, or a struct constructed from the preceding types.

variable_dims

Logical vector that specifies whether each dimension is variable size (true) or fixed size (false).

Default: false(size(sz)) | sz==Inf

Output Arguments

t

coder.Type object

Examples

Create a type for a simple fixed-size 5x6 matrix of doubles.

coder.typeof(ones(5, 6))         
 % returns 5x6 double
coder.typeof(0, [5 6])           
 % also returns 5x6 double
 

Create a type for a variable-size matrix of doubles.

coder.typeof(ones(3,3), [], 1)    
% returns :3 x :3 double
% ':' indicates variable-size dimensions
 

Create a type for a structure with a variable-size field.

x.a = coder.typeof(0,[3 5],1);
x.b = magic(3);
coder.typeof(x)
% Returns 
% coder.StructType
%    1x1 struct
%      a:  :3x:5 double
%      b:  3x3  double
% ':' indicates variable-size dimensions
 

Create a type for a matrix with fixed-size and variable-size dimensions.

coder.typeof(0, [2,3,4], [1 0 1]);
% Returns :2x3x:4 double 
% ':' indicates variable-size dimensions
 
coder.typeof(10, [1 5], 1) 
% returns double 1 x  :5
% ':' indicates variable-size dimensions
 

Create a type for a matrix of doubles, first dimension unbounded, second dimension with fixed size.

coder.typeof(10,[inf,3]) 
% returns double:inf x 3
% ':' indicates variable-size dimensions
 

Create a type for a matrix of doubles, first dimension unbounded, second dimension with variable size with an upper bound of 3.

coder.typeof(10, [inf,3],[0 1]) 
% returns double :inf x :3
% ':' indicates variable-size dimensions
 

Convert a fixed-sized matrix to a variable-sized matrix.

 coder.typeof(ones(5,5), [], 1) 
% returns double :5x:5
% ':' indicates variable-size dimensions
 

Create a nested structure (a structure as a field of another structure).

S = struct('a',double(0),'b',single(0))
SuperS.x = coder.typeof(S)
SuperS.y = single(0)
coder.typeof(SuperS)  
% Returns 
% coder.StructType
% SuperS:  1x1 struct
%   with fields 
%      x:  1x1 struct
%         with fields
%             a: 1x1 double
%             b: 1x1 single
%      y:  1x1  single
 

Create a structure containing a variable-size array of structures as a field.

S = struct('a',double(0),'b',single(0))
SuperS.x = coder.typeof(S,[1 inf],[0 1])
SuperS.y = single(0)
coder.typeof(SuperS)  
% Returns 
% coder.StructType
% SuperS:  1x1 struct
%   with fields 
%      x:  1x:inf struct
%         with fields
%             a: 1x1 double
%             b: 1x1 single
%      y:  1x1  single
% ':' indicates variable-size dimensions

Tips

  • If you are already specifying the type of an input variable using a type function, do not use coder.typeof unless you also want to specify the size. For instance, instead of coder.typeof(single(0)), use the syntax single(0).

See Also

| |

Was this topic helpful?