How can I add only a certain amount of instances of a custom library block to my model?

2 views (last 30 days)
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

Accepted Answer

Fangjun Jiang
Fangjun Jiang on 14 Mar 2022
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.

More Answers (0)

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!