Conditional Simulink Block Deletion?
2 次查看(过去 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!