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

11 visualizaciones (últimos 30 días)
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?

Respuesta aceptada

Benjamin Thompson
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.
  1 comentario
Bogdan Molchanov
Bogdan Molchanov el 3 de Mzo. de 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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Simulink Functions en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by