필터 지우기
필터 지우기

Simulink - Bus Creatro - how to set unused bus to "zero"?

조회 수: 11 (최근 30일)
Michael Felger
Michael Felger 2023년 8월 24일
댓글: Yash Sharma 2023년 9월 13일
Hi,
in my model, I use many buses with many more signals, which go to different subsystems.
For different testcases, only some of the buses / subsystems are used. All others unused buses / blocks can have zero as input.
Is it possible to set a bus to "zero" with a single block?
I usually use the "ground" block for unused signals: https://de.mathworks.com/help/simulink/slref/ground.html
Under supported "Data Types", also bus is mentioned. But in my model, I get an error.

답변 (1개)

Yash Sharma
Yash Sharma 2023년 8월 28일
편집: Yash Sharma 2023년 8월 29일
I understand that you have many buses, and you want to set some of the signals in those buses to zero.
You can use the “MATLAB function block” to set signal values to zero.
Follow the steps mentioned below to achieve it.
  1. Add a MATLAB Function block to your Simulink model.
  2. In the MATLAB Function block, define the input and output ports to match your bus object.
  3. Inside the MATLAB Function block, write MATLAB code to set the values of the bus signals to zero.
Refer to an example code attached below:
function busOutput = setBusToZero(busInput)
% Set all signals of the bus to zero
busOutput = busInput;
busOutput(1) = 0;
busOutput(2) = 0;
% ... repeat for all signals in the bus
end
4. Connect the input bus object to the input port of the MATLAB Function block and connect the output port of the MATLAB Function block to the desired subsystem or destination in your model.
By using a MATLAB Function block, you can manually set all signals of a bus to zero with a single block, providing more flexibility compared to the "Ground" block.
For more information refer to the documentation link of MATLAB Function Block attached below:
  댓글 수: 3
Dana Schwanke
Dana Schwanke 2023년 9월 13일
The method above is horribly inconvenient. We use buses that sometimes have dozens or more elements. In C, if you want a default struct whose values are all zero, it's a one-liner:
struct_type x = {0};
You really don't have something like this for MATLAB or Simulink?
Yash Sharma
Yash Sharma 2023년 9월 13일
If you want to set all values to zero you can use the "Bus Assignment Block" along with a constant block with signal 0, then select all the signals and set them to zero.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Subsystems에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by