Define Types of Entry-Point Inputs by Using the MATLAB Coder App - MATLAB & Simulink (original) (raw)

You can use the MATLAB® Coder™ app to define the types of input arguments to MATLAB entry-point functions. You can also use the app to view input type definitions, set size constraints, control the number of output arguments, or define constant input variables. Alternatively, you can specify input types by using the codegen command with -args at the command line or in your MATLAB code by using arguments blocks or assert statements. For an overview of these methods of input type specification, see Specify Types of Entry-Point Function Inputs.

Define Input Types

To define input types in the MATLAB Coder app, add one or more entry points to your MATLAB Coder project. After you add the entry points, the app highlights the entry-point inputs in red to indicate that input types are undefined.

Unexpanded entry-point pane showing function foo

To view details of the entry-point function inputs, expand the Entry Points pane by clicking the arrow to the left of the function signature . In the expanded view, the app displays an error if the input types are not fully defined.

For example, this image shows the signature of entry-point functionfoo, which has three undefined input argumentsa, b, and c, and three output arguments, x, y, andz.

Entry-point pane showing undefined input arguments of function foo

Automatically Define Input Types

To define the input types automatically, use one of these methods:

Manually Define Input Types

To define input types manually, use one of these methods:

Use Function Argument Validation or Preconditioning to Define Input Types

If an entry-point function uses an arguments block orassert statements to define input types, the app uses these definitions by default. To override these definitions, clear the Source input types from function definition check box. For example, this image shows that the app is using an arguments block orassert statements in the entry-point functionbar to define input argument d as a 10-by-10 array of doubles.

Entry-point pand showing function bar with the type of input argument d sourced from information in the MATLAB function.

Define Types for Multiple Input Variables

You can instruct the app to define undefined input variables as either scalar doubles or scalar singles for all entry-point functions or for specific entry-point functions.

To perform this assignment for undefined input variables in all entry-point functions, click the Actions button on the right side of the Entry Points pane. Click Define undefined types as and then Scalar double or Scalar single.

To perform this assignment for specific entry-point functions, click the Actions button to the right of the entry-point function signature. Click Define undefined types as and thenScalar double or Scalar single.

View Input Type Definitions

You can view the entry-point input variable definitions by expanding theEntry Points pane. The app displays the names of the entry-point input variables, and if the variable types are defined, the variable class, size, and other details. For composite types such as structures, cell arrays, or classes, you can expand the display of each variable to view the name, class, and other details of the individual fields, elements, or properties.

For example, this image shows the Entry Points pane for entry-point function foo. Function foo has three input arguments and returns a single output.

Entry points pane showing the defined input types for entry-point function foo.

This table defines some of the symbols that appear in the Entry Points pane.

Indicator Description
The variable has fields, elements, or properties that you can see by clicking the arrow.
{:} Homogeneous cell array (all elements have the same properties).
{n,m} Element {n,m} of a heterogeneous cell array.
:n Variable-size dimension with an upper bound ofn.
:Inf Variable-size dimension that is unbounded.

Set Size Constraints

You can make the dimensions of the entry-point input arguments in your MATLAB Coder project variable size or unbounded when they meet certain size thresholds. By default, these constraints apply only to variables that you define manually, but you can choose to apply these constraints to input variables you define automatically.

To set variable sizing constraints, click the Actions button on the right side of the Entry Points pane and select Constrain Size. In the Set Size Constrains for Input Types dialog box, select the constraints.

To apply the rules to the current type definitions, click Ok. If you change type definitions manually, the rules do not affect the new definitions unless you reapply them.

Define Constant Input Variable

You can define an input variable as a constant. You can generate a constant value by using MATLAB code or by loading the constant from an existing MAT file. Point to a variable in the Entry Points pane, then click the Modes and Actions button . In the Modes section, selectUse Constant.

The code generator evaluates constant values and defines constant input variables at code generation time. Therefore, if you change the value of the source variable in the MAT file or if the result of the MATLAB command changes after code generation, the value of the constant variable does not update in the generated code.

For example, this image shows the Entry Points pane for functionfoo, which has three constant input arguments:

Entry points pane showing the entry-point function foo with two enabled output arguments

Use an Entry-Point Function Output Type as an Entry-Point Function Input Type

If you generate code for multiple entry-point functions, you can use the output of one entry-point function as the input to another entry-point function.

Click the Modes and Actions button to the right of the variable that you want to define using the output of another entry-point function. In the Modes section, select Use Output. Enter the name of the function that produces the input value in the Function Name box and enter the name of the output variable in the Output Name box. Alternatively, expand the Function Name and Output Name boxes and select the function and output variable.

The app populates the class definition with the call to coder.OutputType that produces the type of the input value. See Pass an Entry-Point Function Output as an Input.

For example, this image shows the Entry Points pane for entry-point functions foo and bar. The input argument a to function foo has the same type as the first output of function bar.

Entry points pane showing the entry-point functions foo and bar, where the output of bar is used to define the type of the inputs to foo.

See Also

MATLAB Coder | arguments | assert | codegen | coder.OutputType

Topics