Effacer les filtres
Effacer les filtres

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

11 vues (au cours des 30 derniers jours)
Michael Felger
Michael Felger le 24 Août 2023
Commenté : Yash Sharma le 13 Sep 2023
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.

Réponses (1)

Yash Sharma
Yash Sharma le 28 Août 2023
Modifié(e) : Yash Sharma le 29 Août 2023
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 commentaires
Dana Schwanke
Dana Schwanke le 13 Sep 2023
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 le 13 Sep 2023
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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Subsystems dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by