Selecting bus signal from variable in Simulink

Hello,
I have a question regarding the selection of a specific bus signal. The selection is not the same from time to time, thus the "Bus selector"-block can not be used.
What I'm looking for is something that corresponds to the "Selector"-block for vectors where the ability to select an index is possible with the use of scalar (or some index).
I've defined my own bus object as e.g. A = [foo foo1]. A.foo = [10 11]; A.foo1 = [20 21];
During simulation I woluld like to make the selection of both e.g. A.foo(1) or A.foo1(2).
I believe there is a solution to this, since a bus object can be viewed as a data struct, and one can solve it via a matlab-script by e.g. Say that A is indata, and defined as before:
"function out = bus_selector(A)
WantedValue = SelectorVariable.FieldNumber WantedField = find(fieldnames(A),SelectorVariable.FieldName);
Out = A.{WantedField}(WantedValue)"
Thus, how can I make this possible in Simulink?
Any help much appreciated. Thank you
Sincerely, Pär Hammarlund

 Respuesta aceptada

Kaustubha Govind
Kaustubha Govind el 20 de Sept. de 2011

0 votos

AFAIK, this is not possible in Simulink. The reason that dynamic selection of bus elements cannot be supported is because bus signals are an aggregate of signals that can each be of different datatype, complexity or dimensions - this means that the datatype/complexity of the output of the Bus Selector cannot be determined up-front at compile-time. Currently it is only possible to vary the dimensions of a signal, but not datatype/complexity, during model run-time. If all your bus elements have the same properties (and are either scalars or 1-D vectors), then you can use the "Bus to Vector" block to flatten out your bus, and then use the regular Selector block to select signals dynamically.

1 comentario

Pär
Pär el 21 de Sept. de 2011
Thank you for your answer.
I tried that way also, but that forces me to keep track of the number of elements in the vector, which I don't want.
But it is possible to sort it out with a stateflow.
Thank you!

Iniciar sesión para comentar.

Más respuestas (1)

Guy Rouleau
Guy Rouleau el 20 de Sept. de 2011

0 votos

Use the MATLAB Function block (previously called Embedded MATLAB Function block).
This does not work exactly as you describe, but it should be possible to make what you want happen.
See the documentation titled "Working with Structures and Bus Signals in MATLAB Functions" to get started:

1 comentario

Pär
Pär el 21 de Sept. de 2011
Thank you!
I'll look into that, I believe that it is possible to get it done with a stateflow.
Thank you.

Iniciar sesión para comentar.

Productos

Preguntada:

el 20 de Sept. de 2011

Community Treasure Hunt

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

Start Hunting!

Translated by