Subtracting a vector from a variable-sized matrix in Simulink issue
Afficher commentaires plus anciens
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 commentaire
dpb
le 16 Fév 2026 à 17:37
Does seem like the perfect place to use a S-function, though, despite the wish. "If frogs had wings..." <g>
Réponse acceptée
Plus de réponses (1)
Fangjun Jiang
le 16 Fév 2026 à 18:13
Modifié(e) : Fangjun Jiang
le 17 Fév 2026 à 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 commentaires
Kadir
le 18 Fév 2026 à 20:27
Fangjun Jiang
le 20 Fév 2026 à 15:58
Modifié(e) : Fangjun Jiang
le 20 Fév 2026 à 16:08
For-loop is not necessarily slow. I just realized that we could loop through the 3 columns. It becomes simple and elegant.


Catégories
En savoir plus sur Array and Matrix Mathematics dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!