How to pass mask parameters to a Enumerated Constant?

8 次查看(过去 30 天)
Hello all,
I want to put an enumerated constant block into a subsystem. This subsystem has a mask in which the parameters for the Enumerated Constant Block are passed.
Masked Subsystem:
The mask parameter "Enum" is a from type unidt (data type Enumerated). The mask parameter "Value" is from type edit and should represent the enumeration value without the enumeration class (means for example Positive instead of SlDemoSign.Positive).
Inside the subsystem there is a enumerated constant and a convert block. The mask parameters should get passed to the enumerated constant block. If I configure it like below then I get an error.
Error message:
My question is: What do I have to do, that I can pass the mask parameters to the enumerated constant block without gettings erros?
Thank you!

回答(1 个)

Tejas
Tejas 2024-2-21
Hello Daniel,
I hope this message finds you well.
Below is the detailed explanation on how to pass mask parameters to the 'Enumerated Constant' block in Simulink. To illustrate this process clearly, I have created a sample Simulink model. Within this model, 'Enumerated Constant' block, which I have named as 'E_Const', is nested inside a subsystem.
Screenshot of Subsystem:
Screenshot of Simulink model:
A 'Display' block is connected to this subsystem, allowing us to view the output value of the 'Enumerated Constant' block with ease.
Let's begin by setting up the foundation for passing parameters from the mask. The first step involves creating a class in MATLAB that encapsulates all the potential values the 'Enumerated Constant' block can assume. Taking the above issue as a reference, I have chosen the following values: 'Negative', 'Zero', and 'Positive'.
The corresponding class file has been titled 'S1DemoSign.m'. Below is the code that defines it:
classdef S1DemoSign < Simulink.IntEnumType
enumeration
Negative(-1)
Zero(0)
Positive(1)
end
end
As a next step, create a mask parameter named 'EnumValue'. This parameter will be of the 'popup' type, allowing us to select a valid value for the 'Enumerated Constant' block from a dropdown menu. You can set up the parameter by entering the enumeration values as demonstrated in the screenshot provided below.
Moving on to the mask's Initialization section, we'll employ the 'set_param' function. This function allows us to dynamically adjust the value of the 'Enumerated Constant' block. The code snippet below illustrates how this is achieved:
enumValue = get_param(gcb, 'EnumValue');
set_param([gcb '/E_Const'], 'Value', ['S1DemoSign.' enumValue]);
Below I have included screenshots showcasing the system's output.
Hope it helps!

类别

Help CenterFile Exchange 中查找有关 Subsystems 的更多信息

产品


版本

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by