Simulink: 'getDegaultValue' method for custom enumeration does not work

8 views (last 30 days)
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?

Accepted Answer

Benjamin Thompson
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.
  1 Comment
Bogdan Molchanov
Bogdan Molchanov on 3 Mar 2022
thank you for the reply! I searched far and wide about enumerations but did not find until now that they can be stored ina dictionary. Migrating to data dictionary does not look like a straightforward approach at a first glance and might defy the purpose of the task

Sign in to comment.

More Answers (0)

Categories

Find more on Simulink Functions in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!