Define and Use Structure Parameters in Simulink
12 views (last 30 days)
Show older comments
Hi,
I wanted to use the method in
to import a struct into a matlab funciton block as I am not really familiar with busses (and the help examples I found weren't really on point as I didn't want to create the struct in simulink, I want to read in a struct created in the workspace into simulink and use it in a function block). This help was referenced in some forum posts I found on this site (I can see this issue comes up but I couldn't get the solutions to work for me, so I must be missing something).
When I follow the guide in the above link, i get the error
----------------------------------------
Parameter struct has a value of an unsupported type Parameter Data 'struct'
Component:MATLAB Function | Category:Coder error
----------------------------------------
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/855635/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/855640/image.jpeg)
Is anyone able to assist with where I have gone wrong?
0 Comments
Accepted Answer
Paul
on 6 Jan 2022
Do you actually have a variable in the base (or model, I suppose) workspace named 'struct'? That would be odd because struct is a built-in function, and normally one doesn't name variables to override built-in function names.
The function signature in the block should be:
[FX,FY,MZ] = solve_function(GAMMA,FZ,alpha_deg,k,mystruct)
mystruct needs to be defined in the base workspace (or I think it can be in the model workspace), and the Scope of mystruct should be set to Parameter in the Ports and Data Manager.
4 Comments
Jan Los
on 14 Mar 2024
After searching for hours with a similar "coder error" bug, i found this is the solution.
I added text somewhere in the structure, and this is apparently not allowed in Simulink.
Very strange and unnecessary limitation in my humble opinion. Cleaning up an existing parameter structure from all text to be able to use it in Simulink is annoying and eliminates the significant advantage of having descriptive entries in the structure.
Moreover, it would be very nice if Simulink throws a more descriptive error than simply "coder error".
engdancili
on 18 Sep 2024
@Jan Los great! I had the same issue and I quickly solved thanks to your comment. I wish there was the possibility to upvote comments.
More Answers (0)
See Also
Categories
Find more on Simulink Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!