Unable to extract simulink block paths in my model

1 次查看(过去 30 天)
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