How to set instance parameters of a referenced model _with varying dimension_?

7 views (last 30 days)
I've configured a model to expose a parameter data as described here: Parameterize a Referenced Model Programmatically:
set_param(block, param, 'data')
modelWorkspace = get_param(model, 'ModelWorkspace');
assignin(modelWorkspace, 'data', Simulink.Parameter([1.0 2.0 3.0]));
...
set_param(model, 'ParameterArgumentNames', 'data')
Later I submit a new value to the parameter (note that the size is now [1 4] instead of [1 3]!):
instSpecParams = get_param(modelReference, 'InstanceParameters');
instSpecParams(1).Value = '[0.0, 1.0, 2.0, 3.0]' % Let's say that the first entry has .Name == 'data'.
set_param(modelReference, 'InstanceParameters', instSpecParams);
This results in the following error:
Invalid dimensions for parameter argument 'data' of Model block 'model/block'. The parameter provided is a [1x4] array but a [1x3] array is expected.
Apparently, you have to submit a value with the same size as the original Simulink.Parameter object. I have a couple of questions:
1) Is this expected behavior? (Given that I can change the Value field of a Simulink.Parameter at any time, but can't do it in this settings, I have my doubts about this.)
2) What's the correct approach to solving the problem described above? In other words: How can I change parameters of a referenced model with values of varying dimension?
3) The Simulink.Parameter has a field Dimension which just double-books the size of the Value field. What's the purpose of this field?
Note: The block I'm configuring is a 1-D Lookup Table, and I'm configuring the breakpoints and table data, in case that makes a difference. For the record: I'm exposing some other parameters of the model, and I'm always setting the Table and BreakpointsForDimension1 parameters to vectors of the same size. If absolutely necessary, I can provide a minimal counter example.

Answers (1)

Harimurali
Harimurali on 28 Mar 2024 at 12:54
Hi Malte,
I am unable to reproduce this issue. I tried with MATLAB R2020a version and the latest MATLAB R2023b version. I was able to programmatically set the value of the instance-specific parameter of the model that references another in both the versions.
A workaround for this is to set the instance-specific parameter in the Simulink model by following the given steps:
  • Open the model that references the model with the "1-D Lookup Table" block.
  • Right click on the "Model" block and select the "Block Parameters" option.
  • Navigate to the "Instance parameters" section in the "Block Parameters" dialog box.
  • You can change the value of the desired instance-specific parameter here, in this case the value of "data".
Refer to the following documentation for more information about the "Model" block: https://www.mathworks.com/help/releases/R2020a/simulink/slref/model.html
The "Dimensions" property of the "Simulink.Parameter" object stores the dimensions of the value stored in the "Value" property, returned as a row vector or specified as a character vector. When you set the "Value" property of the object, the object sets the value of the "Dimensions" property to a "double" row vector. The vector is the same vector that the "size" function returns.
Hope this helps.

Categories

Find more on Dependency Analysis in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!