What is the Matlab code that connects a variable to a Slider Switch Block?

3 ビュー (過去 30 日間)
형조
형조 2025 年 2 月 13 日
編集済み: Fangjun Jiang 2025 年 2 月 15 日
What is the Matlab code that connects a variable to a Slider Switch Block?
I tried using the code below, but it failed. Please give me a lot of advice.
modelName = 'mdl';
open_system(modelName);
modelWorkspace = get_param(modelName, 'ModelWorkspace');
modelWorkspace.assignin('A', 0);
scenarioSwitchPath = [modelName '/Scenarios/ScenarioSwitch'];
set_param(scenarioSwitchPath, "Binding", 'A');

回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2025 年 2 月 14 日
編集済み: Fangjun Jiang 2025 年 2 月 14 日
The 'binding' needs to be a block in the model. If that block uses 'A' as a parameter and that parameter is selected to be bound, then it is effectively bound to 'A'.
Make an example model and bind a parameter, make sure it works properly and then get_param(BlockPaht,'binding') to figure out how to set it programingly.
Or check the help document of the Slide Switch block, "Parameters",'Connection", "Programmatic Use" section

カテゴリ

Help Center および File ExchangeSimulink Functions についてさらに検索

タグ

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by