coder.OutputType - Output type from an entry-point function to specify as an input type - MATLAB (original) (raw)
Main Content
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
Syntax
Description
t = coder.OutputType([func](#mw%5F390adb5d-5cf9-4e17-9fa5-55aba593df77))
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](#mw%5F390adb5d-5cf9-4e17-9fa5-55aba593df77),[n](#mw%5F0ff3b76f-1a6a-442b-bf1f-c5f36e67f82e))
creates an object that is derived from the coder.OutputType
class to represent the n
-th output of the entry-point functionfunc
.
Input Arguments
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
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
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 usingcoder.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
. Usecoder.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.
Version History
Introduced in R2018b