setVariable Failing to set Parameter

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?

답변 (1개)

Josh Kahn
Josh Kahn 2026년 2월 25일 13:52
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)
defaultOutput = 12
% Try again with simIn
simIn = Simulink.SimulationInput(modelName);
simIn = simIn.setVariable(paramName, 15);
simOut = sim(simIn);
modifiedOutput = simOut.yout{1}.Values.Data(1)
modifiedOutput = 15

카테고리

도움말 센터File Exchange에서 Manage Design Data에 대해 자세히 알아보기

제품

릴리스

R2024b

태그

질문:

2026년 2월 18일 15:52

답변:

2026년 2월 25일 13:52

Community Treasure Hunt

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

Start Hunting!

Translated by