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

2 次查看(过去 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

采纳的回答

Fangjun Jiang
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 CenterFile Exchange 中查找有关 Sources 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by