What is the proper syntax to include an enum data type in a Simulink parameter?

9 次查看(过去 30 天)
I have a Simulink parameter that I've imported to the model workspace and is data type struct. It's going to be used as a bus output from a constant block in the model, outputting a bus that is stored in a data dictionary, and will be used with a Bus Assignment block being sent to the 'bus' input port.
The problem I'm running into is that the bus I want to use contains an enumerated data type. I manually edited my parameter object to include the necessary data, but I don't know what to use here to make it accept an enum. I know that these can store data with multiple dimensions, because I've worked on a similar project where that was done, but I have no reference for how to use an enum.
Input_1 = Simulink.Parameter;
saveVarsTmp{1} = struct;
saveVarsTmp{1}.flag = 0;
saveVarsTmp{1}.data = struct;
saveVarsTmp{1}.data.camAttStd = single(0);
saveVarsTmp{1}.data.camPosStd = single(0);
saveVarsTmp{1}.data.mapStd = single(0);
saveVarsTmp{1}.data.timingJitterStd = single(0);
saveVarsTmp{1}.data.camIntStd = single(0);
saveVarsTmp{1}.data.terrain = single(0); % <--- This value needs proper syntax for type enum
Input_1.Value = saveVarsTmp{1};
Input_1.CoderInfo.StorageClass = 'Auto';
Input_1.CoderInfo.Alias = '';
Input_1.CoderInfo.Alignment = -1;
Input_1.CoderInfo.CustomStorageClass = 'Default';
Input_1.CoderInfo.CustomAttributes.ConcurrentAccess = false;
Input_1.Description = '';
Input_1.DataType = 'Bus: errConfig_IO';
Input_1.Min = [];
Input_1.Max = [];
Input_1.DocUnits = '';
clear saveVarsTmp;
The data named "terrain" is an enum holding about 10 different values, while all other data is just floats. Can anyone help me with the proper syntax here? I have been combing the documentation and have found lots of info for handling enums in different places in Matlab, but never on this format within a Simulink parameter.

采纳的回答

George Pence
George Pence 2018-2-1
I discovered a method that doesn't need Simulink parameters whatsoever... it was actually such a simple thing, yet I would have never found it by reading online.
If you set a constant block's value field to 0, you can then safely output any bus object data, regardless of if it has mixed types, enums, anything. So instead of this awful roundabout way of outputting buses from a constant via structs manually defined in the model workspace, all I needed was a 0.

更多回答(1 个)

ES
ES 2018-2-1
https://in.mathworks.com/help/simulink/slref/simulink.aliastype.html
  2 个评论
George Pence
George Pence 2018-2-1
Would you mind clarifying? An alias type could be useful here but I still don't know how to format the specific syntax on the line of code I need.
Would it be saveVarsTmp{1}.data.AliasName = single(0); ?? And then store the alias in the workspace along with the Simulink struct parameter?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Simulink Functions 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by