Is there a way to select variant choice using a simulink signal instead of constants?

6 views (last 30 days)
Hello, i have a simulink block diagram, that has a logic gives 1 or 2 in the simulation time with given inputs. I want to use this number to select between my varient choices, using the logic output that is changing in simulation time. İ cannot find a way to do it. It wants me to create a constant for variant selection, but it is not a constant number in my case.
  2 Comments
Mathieu NOE
Mathieu NOE on 17 Dec 2024
hello
use logical blocks like comparator so your "1 or 2" signal will be converted into logical signals you can use then to select blocks or signals
metehan akinci
metehan akinci on 17 Dec 2024
Variant subsystem block does not have an inport port to let me chosee the varient selection. That is the problem

Sign in to comment.

Accepted Answer

Aravind
Aravind on 18 Dec 2024
It sounds like you are looking to select between two subsystems based on the value of a specific signal.
In the R2023b release, the "Variant Subsystem" block does not support changing the active subsystem during runtime, as the variant expression is evaluated before the simulation begins. However, starting with R2024b, the "Variant Subsystem" block allows for runtime evaluation of the variant control expression, enabling you to switch between subsystems dynamically based on a signal's value. To achieve this, you can set the "Variant control expression" to evaluate based on a variable in the model workspace, and then use the "Parameter Writer" block to dynamically update this variable to match the signal of interest. More details about the "Parameter Writer" block can be found here: https://www.mathworks.com/help/simulink/slref/parameterwriter.html.
When using this method, ensure that the "Variant activation time" parameter of the "Variant Subsystem" block is set to "runtime" and that the "Treat as atomic unit" option is enabled for each subsystem within the "Variant Subsystem" block.
Alternatively, in R2023b, you can use the "If Action Subsystem" block to switch between subsystems based on a signal. This block functions like an if-statement in programming, activating a specific subsystem depending on whether the "If Block" evaluates to true or false. This allows you to use a signal's value to toggle between desired subsystems. For more information on the "If Action Subsystem" block, visit the following documentation page: https://www.mathworks.com/help/releases/R2023b/simulink/slref/ifactionsubsystem.html. You can also refer to an example here.
I hope this clarifies your question.

More Answers (0)

Categories

Find more on Component-Based Modeling in Help Center and File Exchange

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!