How to pass mask parameters to a Enumerated Constant?
7 views (last 30 days)
Show older comments
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!
0 Comments
Answers (1)
Tejas
on 21 Feb 2024
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.
To know about ‘set_param’ function , refer to this documentation : https://www.mathworks.com/help/releases/R2018b/simulink/slref/set_param.html?&s_tid=doc_srchtitle#:~:text=See%20Also-,set_param,set_param(model%2C%27SimulationCommand%27%2C%27Update%27),-For%20parameter%20names .
Hope it helps!
0 Comments
See Also
Categories
Find more on Subsystems in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!