Unable to extract simulink block paths in my model

조회 수: 1 (최근 30일)
Suresh
Suresh 2022년 11월 8일
댓글: Suresh 2022년 11월 10일
Hi all,
I have one model, in that i would like to extract yellow colour background simulink block paths (only need path) only in all levels,
but i unable to do that, can u pls help me.
here is my code
[model_name, path] = uigetfile('*.slx','Select the model file')
modelname = model_name(1:end-4)
load_system(model_name)
dpath = find_system;
%Model_Subsystem = find_system('SearchDepth',3,'regexp','on','BackgroundColor','Yellow')
Model_Subsystem = find_system(modelname,'BlockType','Subsystem')
subsys_colour = get_param(Model_Subsystem,'BackgroundColor')
for i = 1:length(subsys_colour)
if strcmp(subsys_colour{i},'Yellow')
new_path = subsys_colour{i}
end
end

채택된 답변

Nishan Nekoo
Nishan Nekoo 2022년 11월 10일
편집: Nishan Nekoo 2022년 11월 10일
On line 6, it should be 'SubSystem' instead of 'Subsystem'. Instead of using 'strcmp', consider using 'strcmpi' to prevent the case from being an issue. Furthermore, instead of using a for loop, you can leverage indexing as follows:
[model_name, path] = uigetfile('*.slx','Select the model file')
modelname = model_name(1:end-4)
load_system(model_name)
dpath = find_system;
%Model_Subsystem = find_system('SearchDepth',3,'regexp','on','BackgroundColor','Yellow')
Model_Subsystem = find_system(modelname,'BlockType','SubSystem')
subsys_colour = get_param(Model_Subsystem,'BackgroundColor')
paths = Model_Subsystem(strcmpi(subsys_colour,'Yellow'))
Be sure to check out this MATLAB answers post too:
https://www.mathworks.com/matlabcentral/answers/102253-how-can-i-find-all-subsystems-my-model-contains-in-simulink-7-8-r2011b

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by