How to correctly set instance parameters of model reference?

1 次查看(过去 30 天)
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?

回答(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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Automotive Applications 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by