Partitioning parameters for each subsystem

7 views (last 30 days)
I have a subsystem with mask parameters. I am partitioning inputs and parameters for each subsystem.
My model is simple as below which filters each input channel using Biquad filter and parameters different for each inpurt channel as follows:
the parameters of the biquad filter are read on mask as follows:
where 'a' and 'b' are [2X3] and [3X3] array with each row of 'a' and 'b' are used to design one filter to filter one input channel. There are 3 inputs that are filtered that is why the use of each susbsytem block.
I am able to run this model in simulink but having trouble in generating code:
any help is appreciated!

Accepted Answer

Harsh
Harsh on 17 Jul 2025
You’re encountering this issue because, during code generation, Simulink requires each filter coefficient to appear as a fixed scalar or fixed-size vector parameter in the generated C code.
When you write something like "a(1,1)" inside the mask, it means “look up the first element of the tunable matrix a” at runtime. While this works fine in simulation (since MATLAB can dynamically index into arrays), code generation must produce static definitions. Dynamic indexing into a tunable parameter matrix such as "a" isn’t supported.
To fix this, you should explicitly configure all the mask parameters for partitioning in the "For Each Subsystem" block. In the block’s "Parameter Partition" tab, list each parameter (like "a1", "a2", "b0", "b1", "b2") and specify their "Partition Dimension" and "Partition Width".
This way, Simulink knows exactly how to slice these parameters before build time, and the generated code can create static, per-partition variables instead of using runtime indexing.
Below is an example model with the above configurations-
Mask parameters for the "For Each Subsystem"-
Parameter Partition for the "For Each"-
I hope this resolves your query!
  1 Comment
Devyani Varshney
Devyani Varshney on 20 Aug 2025 at 20:11
sorry for late acceptance, I ended up doing the same in 2023.

Sign in to comment.

More Answers (0)

Categories

Find more on Schedule Model Components in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!