Simulink: 'getDegaultValue' method for custom enumeration does not work
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Bogdan Molchanov
le 23 Fév 2022
Commenté : Bogdan Molchanov
le 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 commentaires
Réponse acceptée
Benjamin Thompson
le 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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Simulink Functions dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!