MATLAB Answers

How to correctly set instance parameters of model reference?

2 ビュー (過去 30 日間)
Malte Kliemann
Malte Kliemann 2020 年 10 月 21 日
コメント済み: Malte Kliemann 2020 年 10 月 22 日
According to Parameterize a Referenced Model Programmatically, you can programatically change instance parameters of a model reference ex_model_arg/Model as follows:
instSpecParams = get_param('ex_model_arg/Model','InstanceParameters');
instSpecParams(1).Value = '.98';
instSpecParams(1).Argument = true;
set_param('ex_model_arg/Model','InstanceParameters',instSpecParams);
However, I run into a multitude of problems doing this. First of all, instSpecParams is an 0×1 empty struct array with fields Name, Value, Path, Argument, and it's not supposed to be. I don't know what could cause this. This means that I have to manually fill out all fields before submitting the struct to set_param. The function of Name, Value and Argument are clear.
However, I cannot find any info on what Path is. Furthermore, if I get the InstanceParameters paramter from my own models (not the examples), then there is not Path field, but rather a FullPath field. Ignoring this will lead to the following error (both in the examples and my own model):
To set model parameters, use a structure array with fields 'Name', 'Value', 'FullPath', and 'Argument'.
Again, I cannot find anything on what FullPath is.
To summarize: The documentation appears to be outdated or wrong, or I'm under a grave misapprehension. How can I programatically change instance parameters of a model reference?

  0 件のコメント

サインインしてコメントする。

回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2020 年 10 月 21 日
In the referenced model, you need to create workspace variables, set 'ParameterArgumentNames' first as described in the document. Otherwise, when it is referenced in another model, 'InstanceParameters' will return as an empty structure.
The field name is always "Path" for me for example models and my models in R2020a. The "FullPath" referenced in the error message might be misleading. Try above first to be able to get the structure and then see what is the field name for your model.

  2 件のコメント

Malte Kliemann
Malte Kliemann 2020 年 10 月 22 日
Thanks! That was my bad, didn't read properly. Apparently, you need to set the ParameterArgumentNames parameter, otherwise you get the incorrect fields in the return value.
Malte Kliemann
Malte Kliemann 2020 年 10 月 22 日
Nevermind, the problem persists when trying to use the python engine to perform this task.

サインインしてコメントする。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by