Selecting bus signal from variable in Simulink
Show older comments
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
Accepted Answer
More Answers (1)
Guy Rouleau
on 20 Sep 2011
0 votes
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:
Categories
Find more on Sources in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!