setVariable Failing to set Parameter
Afficher commentaires plus anciens
My Harness has a model ref with it's own model refences, and the harness data dictionary referencess the reference data dictionary.
In one of the lower level model references is a datadictionary parameter which I need to set.
In my script.
I getValue to get the parameter from data dictionary, modify it then use simin.setVariable to set it and then sim or parsim the simIn.
I have confirmed that the simIn object has the correct target value but when simulating can see this is not updated from the default data dictionary value.
I am simulating in Normal mode.
I have tried:
Specifying the workspace to be the reference model workspace
Moving the parameter to the top level data dictionary.
Deleting the work folder contents to force rebuild.
Changing the parameter storage class to ExportedGlobal
Under Model Properties ticking Enable access to base workspace and enforce consistant data definitions.
Opening the data dictionary and changing the value with setValue does work but would prevent efficient batch runs.
What else could be preventing the value from setting?
Réponses (1)
This worked for me, is this different than what you are doing?
Josh
dictionaryName = 'TestDictionary.sldd';
Simulink.data.dictionary.create(dictionaryName);
dictionary = Simulink.data.connect(dictionaryName);
paramName = 'TestParam';
create(dictionary, 'Parameter', paramName);
dictionary.TestParam = 12;
dictionary.saveChanges;
modelName = 'TestModel';
testModel = new_system(modelName);
set_param(modelName,'DataDictionary',dictionaryName);
add_block('simulink/Sources/Constant', [modelName '/Constant'], ...
'Value', paramName, ...
'SampleTime','-1');
add_block('simulink/Sinks/Out1', [modelName '/Out']);
add_line(modelName, 'Constant/1', 'Out/1');
save_system(modelName);
simOutDefault = sim(modelName);
defaultOutput = simOutDefault.yout{1}.Values.Data(1)
% Try again with simIn
simIn = Simulink.SimulationInput(modelName);
simIn = simIn.setVariable(paramName, 15);
simOut = sim(simIn);
modifiedOutput = simOut.yout{1}.Values.Data(1)
Catégories
En savoir plus sur Manage Design Data dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!