How to correctly set instance parameters of model reference?

8 views (last 30 days)
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?

Answers (1)

Fangjun Jiang
Fangjun Jiang on 21 Oct 2020
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 Comments
Malte Kliemann
Malte Kliemann on 22 Oct 2020
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 on 22 Oct 2020
Nevermind, the problem persists when trying to use the python engine to perform this task.

Sign in to comment.

Categories

Find more on Automotive Applications in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!