I made a custome Library block which is basically a masked subsystem. I've put the masked subsystem inside another subytem and in its initialization section i made a code that replicates and connect copies of the custome block according to the wished number.
---------->
In order to achieve this, all the blocks need to be deleted along with the lines connecting each block. To delete the lines i inserted the folowing code which works fine:
lines = find_system(gcb,'SearchDepth','1','LookUnderMasks','On','FindAll','On','Type','Line');
delete(lines);
Now for the customed blocks i can't do the same since it doesnt get recognized. Following code has been tried:
blks = find_system(sys,'SearchDepth','1','LookUnderMasks','On','FindAll','On', 'BlockType', 'SubSystem');
delete_block(blks);
Using Simulink.SubSystem.deleteContents(gcb) i was able to delete everything. However this deletes the ports as well which is something that i dont want to have since any conection with the main subsystem will be terminated. Any idea..?

 채택된 답변

Ahmed Ellithy
Ahmed Ellithy 2023년 5월 7일

0 개 추천

Ok! So i was able to solve the issue by calling the names of the custome blocks by refering them as SubSystems. The find_system() hasn't been used but rather the following:
blks = Simulink.findBlocksOfType(gcb,'SubSystem');
delete_block(blks);
Thanks for Fangjun Jiang for the multiple suggestions regarding this issue

추가 답변 (1개)

Fangjun Jiang
Fangjun Jiang 2023년 5월 7일

0 개 추천

The blks = find_system() will return 4 block handles. The first one is "sys" itself and the next three are the three customized blocks.
delete_block(blks) will delete "sys" first and then give an error message.
You could do delete_block(blks(2:end))
A better way is to give your customized block a unique tag so it is easy to find it. If it is a masked subsystem, then "MaskType" is the right one to use.

댓글 수: 3

Thank you for your respond. Unfortunately i've copied the code wrongly. The actual code has 'gcb' and not 'sys'. I apologies for this mistake :). The actual code lookes like this:
blks = find_system(gcb,'SearchDepth','1','LookUnderMasks','On','FindAll','On', 'BlockType', 'SubSystem');
delete_block(blks);
If i may ask, how do you implement your way with MaskType? I tried replacing the 'BlockType' with it and assigning it to 'On' but it didn't work out. Have i done it wrong?
Fangjun Jiang
Fangjun Jiang 2023년 5월 7일
편집: Fangjun Jiang 2023년 5월 7일
If "gcb" here points to the block "Dynamic/Main System", then it is the same effect.
"MaskType" is at the document page of the Mask Editor. Make it "MyCustomBlock", then search your blocks like find_system(...,'MaskType','MyCustomBlock'). It is used similarly as find_system(...,'BlockType','Gain').
Ahmed Ellithy
Ahmed Ellithy 2023년 5월 7일
Unfortunately it doesnt work as well :(. Is it possible to find the blocks using their names? The name of the custom block is Cable1U and the first block inserted inside the subsystem is Cable1U1 and and increases till the specified number (ie Cable1U999).

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기

제품

릴리스

R2022b

질문:

2023년 5월 7일

답변:

2023년 5월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by