Clear Filters
Clear Filters

How to execute Simulink subsystem only if a specific variable exists in the workspace?

9 views (last 30 days)
I have a Simulink model and 2 different scripts that initialize it. There are some variables that aren't initialized by one script, and are initialized by the other. How would I set up my Simulink model such that a subsystem is executed if a variable that is only initialized by Script 1 is present in the workspace? I found this thread, but even after implementing that I get a compile time Simulink error that says the following. How do I fix this?
Invalid setting in 'MODEL' for parameter 'Value'
> Caused by: Undefined variable foo.

Answers (1)

Moe_2015 on 7 Jul 2022
You can make use of and convert your subsystems to variant subsystems:
In your scripts you can have a variabe called DoesfooExist = exist(foo,'var'). For the variant that the variable exists, in the block parameters of the variant subsystem, set the expression to DoesfooExist == 1. The other variant can be DoesfooExist == 0 and the block just outputting zeros. That way when you use script 1, the block is executed as you want. When using script 2, it will use the variant that does not have that variable.

Community Treasure Hunt

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

Start Hunting!