- 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".
How to set instance parameters of a referenced model _with varying dimension_?
조회 수: 1 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
답변 (1개)
Harimurali
2024년 3월 28일
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:
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Simulink Functions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!