Matlab Simulink how to select elements by matlab script

조회 수: 7 (최근 30일)
Steve Oswald
Steve Oswald 2021년 11월 24일
답변: Simran 2025년 2월 18일 4:30
Hello,
for code testing, I'd like to select elements of a matlab simulink model by matlab code.
I'd expect to get the (line) handle of the selected simulink item returned AFTER selecting the elements by script.
% * code to select constant1 block *
handle_of_constant1 = find_system(bdroot,'FindAll','on','Selected','on');
Thank you in advance!

답변 (1개)

Simran
Simran 2025년 2월 18일 4:30
I see you want to select elements of your Simulink model progammatically and obtain their handles. To do so you can use the “find_system” function. Here is an example on how you can do it:
1.) Open your Simulink model and use the “set_param” function to select the block. Make sure you know the full path of the block within the model.
2.) Then use the “find_system” to get the handle of the selected block.
Here is an example code to help you:
% Open the Simulink model
open_system('your_model_name'); % Replace with your actual model name
% Define the block path
blockPath = 'your_model_name/Constant1'; % Replace with the actual block path
% Select the block programmatically
set_param(blockPath, 'Selected', 'on');
% Retrieve the handle of the selected block
handle_of_constant1 = find_system(bdroot, 'FindAll', 'on', 'Selected', 'on');
% Display the handle
disp(handle_of_constant1);

카테고리

Help CenterFile Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by