Main Content

coder.OutputType

Output type from an entry-point function to specify as an input type

Description

A coder.OutputType object represents the type of an entry-point function output variable. Use coder.OutputType to specify an input for another entry-point function. Pass the input by using the codegen -args option. Do not pass a coder.OutputType object as an input to a generated MEX function.

Creation

Description

example

Note

You can also create a coder.OutputType object interactively by using the Coder Type Editor. See Create and Edit Input Types by Using the Coder Type Editor.

t = coder.OutputType(func) creates an object that is derived from the coder.OutputType class to represent the first output of the entry-point function func.

t = coder.OutputType(func,n) creates an object that is derived from the coder.OutputType class to represent the n-th output of the entry-point function func.

Input Arguments

expand all

Name of entry-point function from which to define the output type.

Example: coder.OutputType('myConstructor')

Index that indicates the n-th output variable of the corresponding entry-point function.

Example: coder.OutputType('myFnWithTwoOutputs',1)

Example: coder.OutputType('myFnWithTwoOutputs',2)

Properties

expand all

Name of entry-point function from which the output type is derived.

Index of entry-point function output from which the output type is derived.

Examples

collapse all

Suppose that you have a function useString that is intended to operate on a variable-size string input. Write a constructor function for a variable-size string. Pass the output as an input to useString by using coder.OutputType.

Write a MATLAB® function useString that performs operations on an input string.

function y = useString(x)
%#codegen
y = replace(x,"be","not be");
end

To construct a variable-size input, write a constructor function.

function str = myConstructor(charArr)
%#codegen
str = string(charArr);

To generate code, specify an input type to the construction function. Declare a variable-size character vector input by using coder.typeof. Use coder.OutputType to represent the output type of the constructor function as the input type to the string operation function.

% get type of var-size char array bounded as 1-by-100
t = coder.typeof('a', [1 100], [0 1]); 
% get output type
v = coder.OutputType('myConstructor');
% generate MEX function
codegen myConstructor -args {t} useString -args {v} -report -config:mex

Test the generated code by calling the MEX function in MATLAB:

a = myConstructor_mex('myConstructor','To be, or not to be.')
b = myConstructor_mex('useString',a)
a = 
    "To be, or not to be."
b = 
    "To not be, or not to not be."

Limitations

  • You cannot use coder.OutputType in the field of a structure, cell, or in an array.

Introduced in R2018b