Oh I think I need to change these parameters from values to variables in the base workspace first. As explained here:
Trying to set parameter values in a Simulink model using a parameter structure
20 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I'm following the docmentation here in an attempt to set up a Simulink model so I can apply a set of parameter values to it before running it from a MATLAB script.
The kind of things I want to set are the parameter values of various blocks such as these:
sim_model = "hw6_p3_RSTsim"; % See file hw6_p3_RSTsim.slx
open(sim_model)
set_param(sim_model + '/Delay', 'DelayLength', string(d));
and
path = sim_model + "/S(z)";
numstr = '['+strjoin(string(S))+']';
set_param(path, 'Numerator', numstr);
set_param(path, 'Denominator', '1');
These commands work fine I just have a lot of them to set so this method seems inefficient. Setting them all in one go from a Parameter Structure sounds like a better way to do this.
The first step says I need to 'Collect all numeric variables used by the model into a MATLAB structure' as follows:
Simulink.BlockDiagram.createVarStruct(sim_model, 'ModelParam')
But this raises the following error:
Error using Simulink.slobject.BlockDiagram.createVarStruct (line 50)
Assertion failed.
Error in Simulink.BlockDiagram/createVarStruct
I have no idea what this means but the code at line 50 is part of a try except block which has the comment: Check that there isn't already a variable with that name.
The following command also doesn't return any variables in the 'base workspace' so this suggests I might be doing something wrong or there is something wrong with my model.
varList = Simulink.findVars(sim_model, 'WorkspaceType', 'base')
Returns:
varList =
0×0 VariableUsage array with properties:
Name
Source
SourceType
Users
If I go into the Model Editor in Simulink I can see the parameters I wish to set:
Risposte (1)
Vedere anche
Categorie
Scopri di più su Configure and View Diagnostics in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!