How can I add only a certain amount of instances of a custom library block to my model?
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello everybody, I hope you are fine and have good wealth.
My question is very simple, but I could not find an appropriate answer yet. I would like to write a custom library and allow the user to instantiate only a certain amount of copies of this block in his model (depending of the memory area he will later access with this block). For example, the user instantiate one block and gives him the number 1, then the next instance and gives him the number 2, and so on, up to a give number of blocks.
I know, this sounds like a very trivial problem, but I could not find an appropriate answer yet. Can someone point me in the right direction please?
Thank you everybody and with best greetings,
Lars
댓글 수: 0
채택된 답변
Fangjun Jiang
2022년 3월 14일
It can be implemented through the "copyfcn" callback of the library block. This function callback is executed every time the libarary block is added or copied to the model. In the function, you can search and find out how many instances of this block has been in the model and then decide what to do.
You may also need to fill in the "deletefcn" callback. Think about what should happen if you delete such an instance from the model.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Sources에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!