Way to Iterate through struct fields for code generation in Matlab Embedded Function for Simulink

1 次查看(过去 30 天)
I have a Struct variable being passed into my Matlab Function inside Simulink, ie:
MyStruct.Field1.(some more fields)
MyStruct.Field2.(some more fields)
...
MyStruct.FieldN.(some more fields)
Each field has a different structure to it so I had created a Bus to allow Simulink to deal with the data and make each field explicitly since Simulink does not allow a Struct array with different field types, but that's besides the point.
My problem is that inside of my Matlab Embedded Function I want to be able to iterate through my Fields since the number of fields for my models can change and I will be calling a subroutine for each one. Currently, I have to explicitly rewrite my embedded function, ie:
subroutine(MyStruct.Field1)
subroutine(MyStruct.Field2)
...
subroutine(MyStruct.FieldN)
Ideally, I wanted to do something like this, but it doesn't work because code generation doesn't allow for it.
numFields = length(fieldnames(MyStruct);
for i = 1:numFields
subroutine(MyStruct.(sprintf('Field%d',i));
end
Problem is that 'fieldnames' and 'sprintf' is not supported for code generation. So I'm stuck looking for another solution.

回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by