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

조회 수: 11 (최근 30일)
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.

답변 (1개)

Moe_2015
Moe_2015 2022년 7월 7일
You can make use of and convert your subsystems to variant subsystems: https://www.mathworks.com/help/simulink/ug/variant-subsystems.html
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.

카테고리

Help CenterFile Exchange에서 Component-Based Modeling에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by