Bus to 2D Vector

8 ビュー (過去 30 日間)
Dimitri
Dimitri 2025 年 8 月 19 日
コメント済み: Dimitri 2025 年 8 月 25 日
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:

採用された回答

Anay
Anay 2025 年 8 月 22 日
編集済み: Anay 2025 年 8 月 22 日
Hi Dimitri,
I understand that you want to access data of each bus individually from a 2-D vector. A quick fix can be to use a “vector concatenate” block to concatenate data of each bus along the column and create the desired 2-D vector. Refer to the images "mdl" amd "subs" to view the necessary changes.
You can consider using an “array of buses so that you can still retain each individual bus and use the bus selectors to access the individual signals in the bus by their name. You can refer to the below link to know more about array of buses in MATLAB documentation:
Hope this helps!

その他の回答 (1 件)

Aryan
Aryan 2025 年 8 月 22 日
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:
  1. Add a Selector block (Signal Routing).
  2. Dimensions = 2 (because matrix has rows + columns)
  3. Row index = port (so the row number comes from the loop index i).
  4. Columns = : (this means all columns). So, at iteration i, the Selector outputs the i-th row of the matrix.
  5. 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 !
  1 件のコメント
Dimitri
Dimitri 2025 年 8 月 25 日
Thanks a lot!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMessages についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by