Define and Use Structure Parameters in Simulink

5 views (last 30 days)
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
----------------------------------------
Is anyone able to assist with where I have gone wrong?

Accepted Answer

Paul
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.
  3 Comments
James Browne
James Browne on 6 Jan 2022
infact, that looks like it was the issue. Even though I wasn't calling the text, its existance in the struct caused the problem.
Jan Los
Jan Los on 14 Mar 2024 at 10:11
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".

Sign in to comment.

More Answers (0)

Categories

Find more on Simulink Environment Customization in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!