Call Simulink Function That is Defined in a Separate Model Using MATLAB Function Block and Model Reference

1 visualizzazione (ultimi 30 giorni)
I have a MATLAB Function block created inside the Model A which call y = Test(u) Simulink Function. And another model called Model B in which Simulink Function y = Test(u) is implemented in.
Now in a seperate model called Simulation I have use two Model block to reference to Model A and Model B, when I update the model an error observed which reference to Model A and say that the Test funciton is undefined.
My question is: Is that possible to call a Simulink Function from a MATLAB Function block that are both implemented in a sepearte model?

Risposte (1)

Suman
Suman il 1 Ago 2024
Modificato: Suman il 1 Ago 2024
Hi Arian,
It is indeed possible to call a Simulink Function from a MATLAB Function block that are both implemented in separate models. The catch is that the models should be in the same branch of the hierarchy.
Let me explain it further by what I mean by "models should be in the same branch of the hierarchy". Before that you should know about the global and scoped visibility of the Simulink Function. Now, I have three models, ref1 (contains the Simulink Function) and ref2 (contains the MALTAB Function block that calls the Simulink Function) and mdlref (also contains the MALTAB Function block that calls the Simulink Function).
Case 1: caller of Simulink Function (i.e., MATLAB Function block) lies below the model in which Simulink Function is defined.
You can see in the Model Explorer that the ref2 model(caller) lies under the ref1 model in hierarchy.
The model in the picture above is ref1 and the referenced model inside it is ref2. Here the caller of the simulink function lies below in the hierarchy. This will work if the visibility of the simulink function is set of global or scoped.
Case 2: caller of Simulink Function (i.e., MATLAB Function block) lies above the model in which Simulink Function is defined.
Here the mdlref model is the caller of simulink funciton and references the ref1 model.
You can see that this time, the caller(mdlref) is above the ref1 in hierarchy. Hence this will only work if the visibility is set to global.
Case 3: models do not lie in same branch of hierarchy.
This is the case you are talking about.
Here the root model, mdlref has references to ref1 and ref2. As you can see in Model Explorer, ref1 and ref2 are on the same level and in different branches if you consider the hierarchy.
This won't work. The caller MATLAB Fuction can't find the Simulink function as it will look above (in it's parent model and so on) and below (referenced child models and so on) in its hierarchy.
I hope that clears your doubts.

Categorie

Scopri di più su Simulink Functions in Help Center e File Exchange

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by