Selecting bus signal from variable in Simulink
Mostrar comentarios más antiguos
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
Más respuestas (1)
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
el 21 de Sept. de 2011
Categorías
Más información sobre Sources en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!