How can I access to the tabs in Simulink editor by script?

조회 수: 21 (최근 30일)
Ivo Kahl
Ivo Kahl . 2020년 7월 28일
댓글: Adam Clark . 2022년 5월 9일
Usually it's possibe to open subsystems by "Open in new tab" by mouse action.
If theese tabs were not closed before saving the model it reopenes in same (all tabs open) way.
I want to create a script (e.g. for usage in pre-save callback), that closes all tabs except the first one.
The necessary command to access theese tabs was not yet found by me.
I'm using ML 2017B with matching Simulink-version.

답변 (2개)

Abhisek Pradhan
Abhisek Pradhan 2020년 11월 13일
I am not sure if this can be done through any of the MATLAB functions but it can be done using some external automation tools, which takes control of MATLAB and can perform various GUI actions.

Alexandre de Langlade
Alexandre de Langlade 2021년 11월 4일
편집: Alexandre de Langlade 님. 2021년 11월 4일
I have just made a script that does exactly that !
Enjoy !
function preSave(system_name)
% preSave PreSaveFcn callback
Blocks_List = find_system(system_name);
% Since we close everything, need to open at least toplevel of
% specified system in case it was not open already
open_system(Blocks_List(1), "tab");
% Index starts at 2 to not close toplevel
for block = Blocks_List(2:end)'
blk = block{:};
% Bonus : Set Zoom factor to fit the window
if strcmp(get_param(blk, 'BlockType'), 'SubSystem')
set_param(blk, 'ZoomFactor', 'FitSystem')
if contains(blk,"/")
if is_stateflow(blk) % Function that checks whether system is a stateflow : look it up if you want
% sfclose considers chart names without toplevel
% name in path, so we remove it
sf_blk = extractAfter(blk,[system_name '/']);
% Finally, set Zoom factor of top level
set_param(Blocks_List{1}, 'ZoomFactor', 'FitSystem')
clear Blocks_List block blk;
  댓글 수: 1
Adam Clark
Adam Clark 2022년 5월 9일
This is great -- Thank you! I've been wanting to do this for years, but finally got around to researching the commands.

댓글을 달려면 로그인하십시오.


Help CenterFile Exchange에서 General Applications에 대해 자세히 알아보기


Community Treasure Hunt

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

Start Hunting!

Translated by