Simulink: 'getDegaultValue' method for custom enumeration does not work
8 views (last 30 days)
Show older comments
Bogdan Molchanov
on 23 Feb 2022
Commented: Bogdan Molchanov
on 3 Mar 2022
Dear helper, here is the outline:
I am simulating ship's operating profile in simulink, where "operating mode" controls the flow of the calculations.
Since there is a finite number of operating modes, I created a custom enumerations as follows (shortened on purpose)
classdef shipModes < Simulink.IntEnumType
enumeration
unknown(0)
seaScantling(1)
seaDesign(2)
seaBallast(3)
seaAnchor(4)
manPort(5)
...
end
methods (Static)
function mode = getDefaultValue()
% GETDEFAULTVALUE Specifies the default enumeration member.
% Return a valid member of this enumeration class to specify the default.
% If you do not define this method, Simulink uses the first member.
mode = shipModes.seaDesign;
end
end
end
When I call this command from Matlab (2021a), works as expected:

When the same command is used in Simulink's Matlab function block I get following error:
'getDefaultValue' is not a valid enumeration name of 'shipModes'. Function 'Power Demand Configurator' (#946.372.381), line 12, column 5: "shipModes" Launch diagnostic report.
Component: MATLAB Function | Category: Coder error
Errors occurred during parsing of MATLAB function 'demandConfigurator/Power Demand Configurator'
Simulink does not complain to usage of for example "shipModes(3)", only to use of methods.
Could that be a Simulink's limitation or I should use another approach?
0 Comments
Accepted Answer
Benjamin Thompson
on 2 Mar 2022
Simulink cannot use MATLAB enumerated class types. Instead you need to define the enumeration in a data dictionary as a Simulink Enumerated Type.
More Answers (0)
See Also
Categories
Find more on Simulink Functions 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!