Subtracting a vector from a variable-sized matrix in Simulink issue
Mostrar comentarios más antiguos
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 comentario
dpb
el 16 de Feb. de 2026 a las 17:37
Does seem like the perfect place to use a S-function, though, despite the wish. "If frogs had wings..." <g>
Respuesta aceptada
Más respuestas (1)
Fangjun Jiang
el 16 de Feb. de 2026 a las 18:13
Editada: Fangjun Jiang
el 17 de Feb. de 2026 a las 12:57
0 votos
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 comentarios
Kadir
el 18 de Feb. de 2026 a las 20:27
Fangjun Jiang
el 20 de Feb. de 2026 a las 15:58
Editada: Fangjun Jiang
el 20 de Feb. de 2026 a las 16:08
For-loop is not necessarily slow. I just realized that we could loop through the 3 columns. It becomes simple and elegant.


Categorías
Más información sobre Array and Matrix Mathematics en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!