Subtracting a vector from a variable-sized matrix in Simulink issue
Ältere Kommentare anzeigen
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 Kommentar
dpb
am 16 Feb. 2026
Does seem like the perfect place to use a S-function, though, despite the wish. "If frogs had wings..." <g>
Akzeptierte Antwort
Weitere Antworten (1)
Fangjun Jiang
am 16 Feb. 2026
Bearbeitet: Fangjun Jiang
am 17 Feb. 2026
0 Stimmen
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 Kommentare
Kadir
am 18 Feb. 2026
Fangjun Jiang
am 20 Feb. 2026
Bearbeitet: Fangjun Jiang
am 20 Feb. 2026
For-loop is not necessarily slow. I just realized that we could loop through the 3 columns. It becomes simple and elegant.


Kategorien
Mehr zu Array and Matrix Mathematics finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!