How do I configure multiple instances of the same referenced model to store values from MAT files?

6 ビュー (過去 30 日間)

I am working on a Simulink project with a controller model that I want to reuse across various parts of my system. This controller is a referenced model, and I need to create multiple instances within a larger system model.
I have a need for shared and individual parameters:Individual: each instance of the referenced controller model needs different parameter values for certain blocks, such as gains or coefficients. I prefer to store this in a struct (one for each controller) for organization, e.g. "struct.var1, struct.var2". This should come from a MAT file.Shared: I have some parameters that need to be the same across all the instances. This could maybe come from another data source, such as a MAT file.
How can I achieve this workflow in Simulink? Where can I store my data, especially my shared and individual parameters?

採用された回答

MathWorks Support Team
MathWorks Support Team 2025 年 3 月 14 日
There are many ways to achieve this, but if you require a struct for each instance, here's what you can do:
At the model reference level:
  • Define the model reference to accept a struct as a Model Argument. (Go into Model Explorer for the model reference, and select the Model Arguments checkbox for the struct)
  • You can create a mask for the model reference if you want an easier interface, such as a dialog box.
  • Configure the blocks to use "struct.<value>"
For more details on using Model Arguments, please refer to the following documentation:
At the top level:
  • Ensure the MAT files have the correct data (shared and individual) for all controllers, wrapped in structs. See "instSpecParamsStruct" from: Group Multiple Model Arguments into a Single Structure
  • Load the structs into the workspace. There are a few approaches:
    • Load the MAT file in the "InitFcn" callback, which brings the structs into the Base Workspace.
    • In the Model Explorer, set the top level model to use a MAT file as a data source, which populates the Model Workspace.
  • Parameterize each masked model reference with "struct1", "struct2", etc.
Note: Simulink Data Dictionaries are more appropriate for models with a large number of parameters, due to easier searching functionalies, hierarchies, and ease of reverting changes. For more information, see: Determine Where to Store Variables and Objects for Simulink Models

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLarge-Scale Modeling についてさらに検索

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by