MATLAB: How to get a unconnected line handle that branching from a normally connected line

handlejunctionsimulinkunconnected line

After deleting the All scope block in the Simulink model programmatically, I tried to delete All the line connected to the scope too, but there is a problem that the line connected normally is also deleted. I want to delete only the unconnected lines that are branched from the normal line. How do I do this?
ScopeBlks=find_system(gcs,'FindAll','On','LookUnderMasks','All','IncludeCommented', 'on', 'BlockType','Scope');
fprintf('Number of Sope block : %d\n', length(ScopeBlks) );
delete(ScopeBlks);
unconnectedLine = find_system(gcs,'FindAll','On','LookUnderMasks','All','IncludeCommented', 'on', 'Type', 'line', 'Connected', 'off');
fprintf('Number of unconnected Line : %d\n', length(unconnectedLine) );
delete(unconnectedLine); % Issue point..

Best Answer

Hi,
I believe if you just want to delete the unconnected portion of the line, you can use delete_line() instead of delete. That will remove only the unconnected part of the line. I tried it out in 2020b release and it works.
Thank you,
Sanket Sheth