フィルターのクリア

Conditional Simulink Block Deletion?

2 ビュー (過去 30 日間)
Craig
Craig 2012 年 9 月 5 日
The aim of the code is to scour a .mdl and delete any mux blocks that are not connected to anything (outport) and then their input signals on that condition. On a side note I am a massive noob.
Start by determining the paths of all the mux blocks:
mux_list = find_system(model_name, 'LookUnderMasks', 'all', 'BlockType', 'Mux')
number_of_mux = size(mux_list);
number_of_mux = number_of_mux(1);
Then proceed with the operation. The operation successfully deletes mux blocks who's outputs are not connected to anything. However, it also deletes mux blocks whose outports are connected to masked blocks (rather than standard blocks) - this is undesirable and is the issue.
if number_of_mux == 0
disp('No Mux detected')
else
muxies=num2cell(zeros(number_of_mux,1)); % memory preallocation.
finalno = number_of_mux
i = 1
for i=1:1:number_of_mux
muxies(i,:)=mux_list(i);
mux_current = char(mux_list(i))
linehandle_current = get_param(mux_current, 'LineHandles');
signal_current = linehandle_current.Inport;
lolcats=get_param(mux_current, 'PortConnectivity')
lolcats=lolcats.DstBlock
deletequery = isempty(lolcats)
if deletequery == 1
delete_line(signal_current);
delete_block(mux_current);
mux_del_list{:,i}=mux_current;
else
finalno = finalno - 1
end
end
disp([num2str(finalno), ' mux(s) of ', num2str(number_of_mux), ' were found and deleted. '])
disp(char(mux_del_list))
end
I presume I need some sort of paradigm shift in my approach to this to get it working as expected.
Best regards,
Brown

採用された回答

Albert Yam
Albert Yam 2012 年 9 月 5 日
Try
mux_list = find_system('test2', 'LookUnderMasks', 'all', 'BlockType', 'Mux');
number_of_mux = size(mux_list);
number_of_mux = number_of_mux(1);
if number_of_mux == 0
disp('No Mux detected')
else
muxies=num2cell(zeros(number_of_mux,1)); % memory preallocation.
finalno = number_of_mux;
i = 1;
for i=1:1:number_of_mux
muxies(i,:)=mux_list(i);
mux_current = char(mux_list(i));
linehandle_current = get_param(mux_current, 'LineHandles');
signal_current = linehandle_current.Inport;
% lolcats=get_param(mux_current, 'PortConnectivity')
% lolcats=lolcats.DstBlock
% deletequery = isempty(lolcats)
deletequery = linehandle_current.Outport == -1; %%ONLY CHANGE
if deletequery == 1
delete_line(signal_current);
delete_block(mux_current);
mux_del_list{:,i}=mux_current;
else
finalno = finalno - 1;
end
end
disp([num2str(finalno), ' mux(s) of ', num2str(number_of_mux), ' were found and deleted. '])
disp(char(mux_del_list))
end
  1 件のコメント
Craig
Craig 2012 年 9 月 6 日
deletequery = linehandle_current.Outport == -1
Thank you for this answer! So LineHandles returns -1 if no line exists - good to know.
Thanks again.
Brown

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgrammatic Model Editing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by