MATLAB Answers

How can I change the active variant subsystem before simulation starts?

8 ビュー (過去 30 日間)
Max Bjurling
Max Bjurling 2017 年 4 月 18 日
コメント済み: Max Bjurling 2017 年 4 月 27 日
I have a model with multiple instances of a variant subsystem. The variant subsystem itself is in a library. How can I choose which variant to use for each instance using a script? Currently I use the PostLoadFcn callback of my top model to set active variant of each instance using set_param(). But if I edit the variant library block (and I do this often), all instances go back to the default variant in my top model. So I need a way to change them back before I run a simulation, and I don't want to have to close and re-open the top model just to do this (invoking the PostLoadFcn callback).
If I use the InitFcn to set the active variant, I get an error that I can't change variant during simulation.

  0 件のコメント

サインインしてコメントする。

回答 (1 件)

Ankit Bhardwaj
Ankit Bhardwaj 2017 年 4 月 26 日
編集済み: Ankit Bhardwaj 2017 年 4 月 26 日
There can be multiple ways to solve this issue.
1. Create an empty subsystem at the top level with an openFcn callback with the same code which you have in postLoadFcn callback. This will be able to fix the variants in one click.
2. You can also think of using Variant objects in the base workspace to fix this issue.

  1 件のコメント

Max Bjurling
Max Bjurling 2017 年 4 月 27 日
Thanks Ankit! Opening an empty subsystem at top level is certainly easier than closing and reopening the entire model. But I would like to do it all using scripts, and since my model will be simulated by my colleagues too it's a bit unintuitive to have to open and close an empty subsystem. Could you elaborate a bit more on your second suggestion?

サインインしてコメントする。

製品

Community Treasure Hunt

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

Start Hunting!

Translated by