Matlab Simulink how to select elements by matlab script
3 views (last 30 days)
Show older comments
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!
0 Comments
Answers (1)
Simran
on 18 Feb 2025
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);
0 Comments
See Also
Categories
Find more on Outputs in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!