Main Content

Explore Measurable and Tunable Model Elements

In this step of the example you explore the model and examine measurable and tunable model elements.

Open the model CapiGetStarted.

capiMdl = "CapiGetStarted";
open_system(capiMdl);

The Sine Wave block generates a signal, which is branched. Each Gain block amplifies one of the branches. The output of the Gain blocks are measurable model signals. During model simulation, the Scope block displays these two signals.

CapiGetStarted model.

Simulate the model and see how the scope plots the two amplified signals.

sim(capiMdl)

Scope displays the two amplified signals.

The gain coefficients are specified as the model parameters Amp_coef_1 and Amp_coef_2. You can tune these parameters to change the amplitude of the amplified signals.

Use the Model Explorer to change the gain coefficient values to 3 and -4 (see Edit and Manage Workspace Variables by Using Model Explorer).

Model Explorer window. The value of Amp_coef_2 is 2, and the value of Amp_coef_1 is being set to -1.

Alternatively, you can change the gain coefficient values programmatically by entering these commands in the Command Window:

workSpace = get_param(capiMdl,"ModelWorkspace");
workSpace.getVariable("Amp_coef_1").Value = 3;
workSpace.getVariable("Amp_coef_2").Value = -4;

Simulate the model again to see how the amplitude of the amplified signals change after modifying the gain coefficient values.

sim(capiMdl)

Scope displays the two amplified signals, denoting the change in amplitude with the revised gain coefficients.

The model signals are measurable, and the model parameters are tunable. In the next step of the example, you configure the model to include the C API elements for them. To continue to the next step of the example, use this in the Command Window:

openExample("simulinkcoder/CapiGetStarted02Example")