In my opinion, the difficulty for users to implement this behavior is in-part due to a problem with word selections. English not being my first language, I sometimes end up in situations where I am not sure which word to use for describing something. I think something similar is happening here.
What does the user really want to do? I think phrasing this need in a different way can help us find the best solution. What about: I want a block that takes one input signal, and assigns it's value to one out of N outputs.
As hinted by the rephrasing above, the Assignment block is what you are looking for. How to use it depends on the behavior you want for the inactive outputs. Let's see a few options.
Option 1: Disabled paths output zero
To begin, drag an Assignment block from the Simulink Library Browser and set its Index Option to Index vector (port)
This will give you a block that takes one input and can assign it to one out of N outputs:
Option 2: Holding the last value externally
What if I want the inactive outputs to hold the last value?
This options makes it clear that the values of the inactive outputs are stored to be reused at the next step.
Warning: Not an option
Here I need to warn you about a method which might seem attractive, but will likely lead to problems.
In the Assignment block, you have the option to set Initialize output (Y) to Specify size for each dimension in table.
Using this option, the Y0 input port will disappear from the block and the block will only write to the selected piece of memory.
If you use this option, ensure that setting the Action if any output element is not assigned parameter to Error does not error out. This diagnostic is to protect against the condition where elements are not assigned, and your algorithm reads from uninitialized memory. During simulation memory is always initialized to zero, but in the generated code, this can be uninitialized and behavior will be non-deterministic.
Now it's your turn
Are there other blocks like the "Reverse Multi-Port Switch" you are looking for? Let us know by leaving a comment here.
コメントを残すには、ここ をクリックして MathWorks アカウントにサインインするか新しい MathWorks アカウントを作成します。