- Add a MATLAB Function block to your Simulink model.
- In the MATLAB Function block, define the input and output ports to match your bus object.
- Inside the MATLAB Function block, write MATLAB code to set the values of the bus signals to zero.
Simulink - Bus Creatro - how to set unused bus to "zero"?
조회 수: 22 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
답변 (1개)
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.
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
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
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.
Bus Assignment: https://www.mathworks.com/help/simulink/slref/busassignment.html
참고 항목
카테고리
Help Center 및 File Exchange에서 Sources에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!