How to change contents of blocks in multiple instances of referenced model in Simulink?

조회 수: 5 (최근 30일)
I am representing a certain robot using a Simulink model which contains Matlab function blocks, integrator blocks, etc., and intend to use this model in a main model. In the main model, I need to have multiple instances of the robot model to represent multiple robots interacting. I have found out that this is possible using referenced models.
However, each of these robots is different. Within each robot model, the architecture does not change, but the contents of the blocks do change to represent the different robots. These changes are not only parameters, but also the contents of the Matlab functions themselves. I generate these functions at the beginning of the simulation using initFcn callback, but I am unaware of how I can update the contents of each referenced model according to the generated functions.
Apologies if the question is confusing, it is not a trivial problem. Thank you in advance for the help!

채택된 답변

Sai 2022년 10월 13일
I understand that you created many sub Simulink models which you will eventually use in main Simulink model as reference model and you are trying to change the contents of blocks correspondingly.
I hope the following explanation resolves the issue.
  • Open the main Simulink model
  • Double click the reference model, which you want to change or update
  • Navigate to Modelling tab and then Model Properties of Model Settings as shown in below image
  • Click on callbacks and then you can add the corresponding files by clicking on different callbacks as shown in below image.
The above process can be repeated for any reference model.

추가 답변 (1개)

Mark McBroom
Mark McBroom 2022년 10월 15일
편집: Mark McBroom 님. 2022년 10월 15일
It is possible to have referenced models use different parameter values by setting them up as parameter arguments. However, it is not possible for different isntances of the reference model to have different code in a MATLAB function.
One possible workaround would be to add a switch statement to your MATLAB code that runs different code based on a pameter ( for example, ModelID)... and then make ModelID a model parameter. This will allow you to give each instance of your referenced model and different ModelID and therefore execute differnt MATLAB code in the MATLAB Function Block.


Help CenterFile Exchange에서 Large-Scale Modeling에 대해 자세히 알아보기




Community Treasure Hunt

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

Start Hunting!

Translated by