Conditional Simulink Block Deletion?

2 visualizaciones (últimos 30 días)
Craig
Craig el 5 de Sept. de 2012
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

Respuesta aceptada

Albert Yam
Albert Yam el 5 de Sept. de 2012
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 comentario
Craig
Craig el 6 de Sept. de 2012
deletequery = linehandle_current.Outport == -1
Thank you for this answer! So LineHandles returns -1 if no line exists - good to know.
Thanks again.
Brown

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Schedule Model Components en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by