Subtracting a vector from a variable-sized matrix in Simulink issue
Show older comments
Hi everyone, I’d like to share a problem I’m facing in Simulink. I have a matrix with a variable number of rows (e.g., [m * 3]), where m is typically around 1000. I need to subtract a [1 * 3] vector from this matrix.
I cannot use the 'Subtract' block directly because of the dimension mismatch. I tried resizing the vector, but since the matrix row count is dynamic, I couldn't find a flexible solution. The vector's dimensions are fixed, but its values change over time, so the 'Bias' block isn't an option. Furthermore, I specifically want to solve this using standard Simulink blocks only, without using a 'MATLAB Function' block.
Has anyone dealt with this type of dynamic broadcasting in Simulink? Any advice on which blocks to use would be greatly appreciated.
1 Comment
dpb
on 16 Feb 2026 at 17:37
Does seem like the perfect place to use a S-function, though, despite the wish. "If frogs had wings..." <g>
Accepted Answer
More Answers (1)
Fangjun Jiang
on 16 Feb 2026 at 18:13
Edited: Fangjun Jiang
on 17 Feb 2026 at 12:57
0 votes
Would "m" vary during a simulation? If not and it only varies between simulations, then you can use the "For Each
Subsystem" block to construct a for-loop in Simulink. Not ideal, but dorable without using the "MATLAB Function" block, which BTW, is perfect to use for your use case.
Or, since it has only 3 columns, the below approach is practical.
Use the "Selector" block to pick out the column, use the "Matrix Concatenate" block to combine the columns.

2 Comments
Kadir
on 18 Feb 2026 at 20:27
Fangjun Jiang
on 20 Feb 2026 at 15:58
Edited: Fangjun Jiang
on 20 Feb 2026 at 16:08
For-loop is not necessarily slow. I just realized that we could loop through the 3 columns. It becomes simple and elegant.


Categories
Find more on Array and Matrix Mathematics 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!