- 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"?
23 次查看(过去 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!