How can I add only a certain amount of instances of a custom library block to my model?
2 views (last 30 days)
Show older comments
Lars Lindner
on 14 Mar 2022
Commented: Lars Lindner
on 14 Mar 2022
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 Comments
Accepted Answer
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)
See Also
Categories
Find more on Sources in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!