Simulink bus selector after add block - simulink

In simulink, you can name a signal and in bus creator you combine them and in bus selector you can decompose them again. The problem is when you add two set of signals to each other. Then, the output of add must be combined signals.
Now, my problem is how to name them after (1 by 1) Add in the way that I can select them from bus selector again?

You can't, it doesn't make sense. Once you have added two signals together, you have a third signal, which you will need to (manually) name. You can't use a bus selector block on the output of an add block to retrieve the initial input signals to the add block.

Related

How to store a specific time that a signal value is changed in another parameter in Matlab simulink?

I have two Matlab function blocks that one is producing zero signal for the other. I want to store the exact time that signal changes to one in another parameter in order to use it elsewhere.
How can I do it?
This type of functinality is achieved using a Triggered Subsystem, as per the image below,
The output of the trigger block will take on value of the input (which in this case is the simulation time) every time the trigger signal rises. Look at the parameters of the Trigger block inside the subsystem for other options such as falling edge, or both edge, triggering.

Simulink math operations on 2 bus signals

I need to make a Simulink block which receives a concatenation of a number of bus signals and performs the same math operations on the signals contained in the bus for each pair of consequent buses. The bus signals are of the same type and are non-virtual.
For the sake of the question, let's assume to have a concatenation of 4 simple buses, each containing a x and a y field. A bus of signals composed of a=x1+x2 and b=y1-y2 need to be made out of buses inputs 1,2 and 3,4. So, the output of the block should be a concatenation of 2 buses, the first containing information from the first pair of input buses, and the second one from the second pair.
An hard-to-scale way to do it is the following.
Are there any built-in Buses Math operations possibilities, or better ways to implement this? I could not find anything in Mathworks documentation, and simple operations block generate incompatibility errors.
You need to use For Each Subsystem Block. As shown in this example. Note that I called the bus BusTest and made the dimension and datatype of signals visible:
Now set the Signal Width parameter of that block to two so it divides input array into chunks of length 2:
Then move your logic into that block:

How to properly propagate multiplex signal names to scope legend via bus system? (Simulink)

I substituted my originial question, the problem is still the same, but the conditions are now different. To review the original question, have a look at the revisions.
I'm looking for a way to interactively select the signals I want to get displayed in my scope Block. The Bus Selector Block with the property Output as Bus does exactly that. I can select all desired signals conveniently without changing any block or signal dimensions.
But the scope block can obviously not handle properly signal names of buses. Therefore my scope legends are wrong:
If I don't set the Output as Bus property and Mux the signal together into the scope block it displays the right signal names. But this is no option as I'd need to adjust the Mux-dimension according to the signals selected.
Are there any workarounds?
(A Floating Scope is no option either)

Append Signal to Bus in Simulink

Is there anyway to simply append a signal to a bus in Simulink? This doesn't seem to be that difficult, but I haven't found a nice way to do it. I can only think of two ways to currently accomplish this:
Select all signals in the bus with a bus selector, then create a bus with all those signals plus the signal to be append using a bus creator. (this is what I am currently doing)
"Pre-allocate" a space in the bus for the signal to be append beforehand then simply replace its value with the value of the actual signal using a bus assignment block.
Is there a reason as to why Simulink cannot append a signal to a bus? Is it because on the backend they are represents as structures (or MATLAB's equivalent) and a property cannot be added to a structure at runtime?
If you are using a bus object, you can use the Bus Editor to add a bus element to an existing bus.

Dynamic wiring in linked block

The problem:
In my simulink model, I have a bus creator that will send all the signals to a block. The block purpose is to make a selector and a switch dynamically based on an index. Example : I have 3 objects, each with a position and a velocity signal, and I want to get the position of the 3 objects, so 3 signals (this means the bus selector will have 3 output and the multi switch will have 4 (one for the index)). The block is working correctly, with a recursive function script called in the callback, it checks the bus for all possible signals and count the number of objects, and modifies the bus selector and the switch accordingly. The problem is that this block is linked to a library, so I have to disable the link in order for the callback script to work.
The questions:
What should i change in order to avoid disabling the link?
Is there another way of making dynamic wiring and don't use a callback script?
I suggest a using vector concatenation block instead of bus creator plus a matlab function block to choose. Here is the model
and here is the code in matlab function:
In this way the block in the library does not need to change each time. Also if you have to keep your buses you can use a bus to vector block to convert them to vector.
The idea of using a MATLAB Function block to do the selecting is a good one, but I would try and stay with a Bus input to preserve the advantages of working with busses, rather than convert to vector and back. So instead of having your code as a callback to the bus selector block, my suggestion would be to implement it in a MATLAB Function block with a bus input and the signal input used to do the selection in the bus, and define the output still as a bus object.