Main Content

slexpr

Generate expression to use in value of parameter object

Description

expressionOut = slexpr(expressionIn) converts the MATLAB-syntax expression expressionIn to an object, expressionOut, that you can use to set the Value property of a parameter object (such as Simulink.Parameter). When you use multiple parameter objects to set block parameter values, you can use the expression to model mathematical relationships between the objects. For more information, see Set Variable Value by Using a Mathematical Expression.

example

Examples

collapse all

In the base workspace, create three Simulink.Parameter objects that represent the mass, length, and moment of inertia of a pointlike metronome.

m = Simulink.Parameter;
r = Simulink.Parameter;
J = Simulink.Parameter;

Set the mass to 0.1 kg and the length to 1.0 m.

m.Value = 0.1;
r.Value = 1.0;

Set the value of the moment of inertia to the mass times the square of the length.

J.Value = slexpr('m*r^2');

Simulink® preserves the expression, m*r^2. If you change the value of the mass or the length, Simulink recalculates the value of the moment of inertia.

Input Arguments

collapse all

Target expression, specified as a string or character vector.

Example: "myParam + myOtherParam"

Data Types: char | string

Output Arguments

collapse all

Simulink representation of the target expression, returned as a Simulink.data.Expression object. A Simulink.data.Expression object has no use outside the Value property of a parameter object.

Version History

Introduced in R2018a