Bus to 2D Vector
显示 更早的评论
Hello!
I have a bus composed of numerous same entities. I used enumerate to create these entities.
Now I want to separately proceed each enumerate entity in a for-loop.
Unfortunately, bus is converted to 1D-vector.
Are there any solutions to convert the bus to 2D-vector?
I've attached an example of simplified model and screen copy:

采纳的回答
更多回答(1 个)
Aryan
2025-8-22
0 个投票
Hi,
In addition to the solution provided by Anay, you may also consider following the steps outlined below.
1. Convert each bus to a vector
- Add a Bus to Vector block (Simulink → Signal Attributes) after each entity bus (id, mode, type, payload).
- Each output becomes a 1×4 vector = [id, mode, type, payload].
2. Make one N×4 matrix
- Vector Concatenate + Reshape : Concatenate all into one long vector, then Reshape to [N 4].
3. Loop through rows (For Iterator Subsystem)
- Drag a For Iterator Subsystem (Ports & Subsystems)
- Connect your [N×4] matrix to its input.
Inside the subsystem:
- Add a Selector block (Signal Routing).
- Dimensions = 2 (because matrix has rows + columns)
- Row index = port (so the row number comes from the loop index i).
- Columns = : (this means all columns). So, at iteration i, the Selector outputs the i-th row of the matrix.
- Add a Demux (4) to split into 4 signals.The row [id, mode, type, payload] is still a vector of 4 numbers.
4. Process signals
- Inside the subsystem, wire id, mode, type, payload into your logic.
Summary:
- Bus → Bus to Vector → (N×4) Matrix → For Iterator Subsystem → Selector → Demux → process each entity.
Hope it helps !
类别
在 帮助中心 和 File Exchange 中查找有关 Messages 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!