MATLAB: How to create a script to automatically delete unconnected lines from the Simulink model in Simulink 7.6 (R2010bSP1)

deletelinessimulinkunconnected

I would like to write a script to delete unconnected lines within the model.

Best Answer

If you would like to see which blocks are unconnected, get a handle to the ports of the block you would like to check, then use delete_line to remove unconnected lines. The example below will try to delete the unconnected Outport blocks within a loop.
open_system('test')
blks = find_system(bdroot, 'Type', 'block');
listblks = get_param(blks, 'BlockType') ;
for i = 1:length(listblks)
if strcmp(listblks(i),'Outport')
lines = get_param(blks(i),'PortConnectivity');
if lines{1,1}.SrcBlock == -1
disp(blks(i))
h = get_param(blks(i),'LineHandles');
delete_line(h{1,1}.Inport);
delete_block(blks(i));
end
end
end