Simulink - change in behaviour of Enumerated Constant block with R2023B?
6 views (last 30 days)
Show older comments
My company is running tests to make sure our old models work with the latest Simulink version. We have a test of all the default block types, and the Enumerated Constant block is giving us an error.
It's set up exactly like the default described in this page : https://www.mathworks.com/help/simulink/slref/enumeratedconstant.html
Enum SlDemoSign with default value SlDemoSign.Positive
When we run the model it gives:
Error in opInitFunction (line 101)
GenerateModel(action, model, platform, preBuildCmd, postBuildCmd, listSub, StandAloneModel, SlxFormat, compilerVersionName); - Show complete stack trace
Caused by:
Error using opInitFunction>CompileModel
'Enum: SlDemoSign' does not resolve to a valid data type for parameter 'OutDataTypeStr' in 'rtdemo1_all_blocks/SS_ALL_BLOCKS/all_sources/Enumerated Constant'. - Show complete stack trace
Error using opInitFunction>CompileModel
Cannot register enumerated data type because value specified is not a class. - Show complete stack trace
Error using opInitFunction>CompileModel
optoolbox.rtlabtools.rtlab_api_helper: INFO: Error evaluating parameter 'Value' in 'rtdemo1_all_blocks/SS_ALL_BLOCKS/all_sources/Enumerated Constant' - Show complete stack trace
Error using opInitFunction>CompileModel
Unable to resolve the name 'SlDemoSign.Positive'. - Show complete stack trace
Running the model and clicking the Enum shows this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1542737/image.png)
Following the instructions here: https://www.mathworks.com/help/simulink/ug/using-enumerated-data-in-simulink-models.html
I was able to get it working by creating a SlDemoSign.m file. I don't know why this is necessary now, though.
classdef SlDemoSign < Simulink.IntEnumType
enumeration
enum1(0)
Positive(1)
end
methods (Static)
function retVal = getDefaultValue()
retVal = SlDemoSign.enum1;
end
end
end
This is a new problem with Simulink R2023B. Our models are all from version R2015B which we can't change because they need to be backwards-compatible.
Does anyone have any insight? Thank you
1 Comment
VIGNESH BALAJI
on 28 May 2024
@Jamie i am also using Matlab R2023B and facing the same problem. Where did you add this file ? Can you please provide me clear instructions for a beginner ?
Answers (1)
Ayush
on 1 Dec 2023
Hi Jamie
I understand that the “Enumerated Constant” block is erroring out by default in MATLAB R2023b which was not the case in the earlier versions.
Based on your exploration, you are on the right path in creating a “SIDemoSign.m” file in your project workspace to define the enumerations class for the block and is the expected behaviour as per the documentation. In earlier versions of MATLAB up until R2023a this file “SIDemoSign.m” was referred by the “Enumerated Constant” block by default. Please refer to the below documentation to know more about how to use enumerated data in Simulink Model:
Upon further investigation, this file/script for the class definition was used by an example present in the root workspace, hence was accessible by the “Enumerated Constant” block by default. It has now been moved to the Example Manager in MATLAB R2023b and hence it is no longer in that path and thus leading to an error.
% In R2023a
>> which SlDemoSign
C:\Program Files\MATLAB\R2023a\toolbox\simulink\simdemos\simfeatures\SlDemoSign.m % SlDemoSign constructor
% In R2023b
>> which SlDemoSign
'SlDemoSign' not found.
Here is the reference for "SIDemoSign.m" that you can use to define an enumerations class in your model's base workspace and resolve this issue across your model.
% In R2023b you can run:
>> openExample('SlDemoSign.m')
% to open the file, which will also show where you can find it now.
Hope it helps,
Regards,
Ayush Misra
See Also
Categories
Find more on String 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!