Simulink: 'getDegaultValue' method for custom enumeration does not work
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Bogdan Molchanov
el 23 de Feb. de 2022
Comentada: Bogdan Molchanov
el 3 de Mzo. de 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 comentarios
Respuesta aceptada
Benjamin Thompson
el 2 de Mzo. de 2022
Simulink cannot use MATLAB enumerated class types. Instead you need to define the enumeration in a data dictionary as a Simulink Enumerated Type.
Más respuestas (0)
Ver también
Categorías
Más información sobre Simulink Functions en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!