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
Best Answer