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 件のコメント
回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!