Unable to extract simulink block paths in my model

1 Ansicht (letzte 30 Tage)
Suresh
Suresh am 8 Nov. 2022
Kommentiert: Suresh am 10 Nov. 2022
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

Akzeptierte Antwort

Nishan Nekoo
Nishan Nekoo am 10 Nov. 2022
Bearbeitet: Nishan Nekoo am 10 Nov. 2022
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

Weitere Antworten (0)

Kategorien

Mehr zu Modeling finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by