Subtracting a vector from a variable-sized matrix in Simulink issue
古いコメントを表示
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 件のコメント
dpb
2026 年 2 月 16 日
Does seem like the perfect place to use a S-function, though, despite the wish. "If frogs had wings..." <g>
採用された回答
その他の回答 (1 件)
Fangjun Jiang
2026 年 2 月 16 日
編集済み: Fangjun Jiang
2026 年 2 月 17 日
0 投票
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 件のコメント
Kadir
2026 年 2 月 18 日
Fangjun Jiang
2026 年 2 月 20 日
編集済み: Fangjun Jiang
2026 年 2 月 20 日
For-loop is not necessarily slow. I just realized that we could loop through the 3 columns. It becomes simple and elegant.


カテゴリ
ヘルプ センター および File Exchange で Array and Matrix Mathematics についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!