Input hierarchical varying length but constant structure into a MATLAB function within Simulink

1 次查看(过去 30 天)
Hi,
I have a hierarchical data structure with lots of sub structures with varying types within them and differing lengths. It represents real aircraft test data and so is not a uniform data set. I need to pass this large structure from a workspace (Matlab or simulink) into my matlab function block within simulink. I've read a lot of different posts on this issue but getting myself very confused so here's a minimum case that produces my error:
Just a lone Matlab function block (in simulink) - With basic set as an inherited parameter in the property inspector with tunable turned off.
function fcn(basic)
basic
In the MATLAB workspace define the basic structure:
basic.deep(1).filename = "test1"; basic.deep(2).filename = "longerString";
Running this provides this error in 2022b:
Mixed field types in structure arrays are not supported. Type at 'basic.deep(1).filename' differed from type at 'basic.deep(2).filename'. Parameter Data 'basic'
Component:MATLAB Function | Category:Coder error
Mixed field types in structure arrays are not supported. Type at 'basic.deep(1).filename' differed from type at 'basic.deep(2).filename'. Parameter Data 'basic'
Despite them both being strings.
For reference my real structure has 29 sub structures each with a Table and sub-sub structure with two fields and variable lengths of data. As this is aircraft data it is constant with time.
I've tried a lot of different ways of importing structures beyond this, trying to create bus objects, trying the data inputs on the model configuration etc. This seems like the right and simplest way so any help would be appreciated!
  1 个评论
Yash Sharma
Yash Sharma 2024-3-22
Hi Joshua,
I believe you are receiving this error due to the varying lengths of the strings. Consider using a cell array instead of strings to address this issue.

请先登录,再进行评论。

回答(1 个)

Pramil
Pramil 2024-9-11
Hi Joshua,
The error you are getting is expected, since the length of both the strings are different, the compiler interprets them as different structures.
You can resolve the issue by either doing one of the following:
  • Use same size character arrays instead of strings. You can decide a maximum array length and add trailing spaces in rest.
And here is the list of datatypes supported for code generation:
I hope this resolves your issue.

类别

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

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by