Conditional Simulink Block Deletion?
1 回表示 (過去 30 日間)
古いコメントを表示
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
0 件のコメント
採用された回答
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
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Schedule Model Components についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!