How format external data for an inport with enum data type defined in data dictionary in Simulink?

3 views (last 30 days)
Hi
I came across this new challenge and I have not been able to solve it, I hope you can help me, thanks in advance for your help!!
I have a simulink model that has an input defined with an Enum data type (for example "weekdays"), the definition of the enum class is stored in a data dictionary and the model runs without problems.
Also I have a vector of data in an excel sheet (for example ['Monday'; 'Tuesday'; ...]), which serve as inputs to the model, I import the data as a string and import the enum definition to matlab, I converted the data to 'int16' that is the same storage type that the enum class has in the data dictionary definition, the problem is that when I try to execute the model it tells me that my type data is incorrect
Error type 'int16' expected 'Enum wekdays'
I am using simulink.signal and dataset (inherent time series) to to supply the data to the model, my next test is to define the enum class in matlab and try to convert the data in matlab with the same enum type, but I feel like there must be a simpler solution

Accepted Answer

Jorge Rojas
Jorge Rojas on 9 Nov 2021
The solution was, import the data to matlab as and array or vector, the enum class was already defined in matlab (I think it's because the class is defined in the *.h file but I'm not 100% sure), with the class defined just evaluate each value in the class to form a timeseries with the correct data type (eg weekdays.monday).
With the correct data type I had no problem simulating the model with that data

More Answers (1)

Fangjun Jiang
Fangjun Jiang on 9 Nov 2021
double click the Inport block, select the "Signal Attributes" tab, in "Data type', pick "Enum: <class name>" and specify your class.

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!