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 Center および File ExchangeModeling についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by