function changeModelParameters(obj)
%

%   Copyright 2008-2023 The MathWorks, Inc.

    modelHsToChange = obj.ModelHsInMdlRefTree;
    index = modelHsToChange==obj.ModelH;
    modelHsToChange(index) = [];
    obj.modelRefInputsMap = containers.Map('KeyType', 'char', 'ValueType', 'any');
    if isempty(modelHsToChange)
        return;
    end     
    
    % We want to respect user-defined setting of AssertControl in
    % general, except the following case.
    if strcmp(obj.UtilityName, 'Validator') &&...
            strcmp(obj.SldvData.AnalysisInformation.Options.Mode, 'PropertyProving')
        % All the assertion blocks included in the property proving
        % analysis as per the SLDV setting DVAssertions will have their
        % block parameter 'Enabled' set to ON or OFF appropriately.
        % For more details on the validation scheme, see the
        % constructor of the class
        % Sldv.Validator.CounterexampleValidatorInPropertyProving.
        paramNameValStruct.AssertControl = 'UseLocalSettings';
    end
    
    paramNameValStruct.UpdateModelReferenceTargets = 'IfOutOfDate';
    paramNameValStruct.SFSimEnableDebug = 'off';
    
    if strcmp(obj.SignalLoggingSaveFormat,'Dataset')
        paramNameValStruct.SignalLoggingSaveFormat = 'Dataset';
    end
    for idx=1:length(modelHsToChange)
        modelH = modelHsToChange(idx);
        modelName = get_param(modelH,'Name');
        currentParamNameValStruct = paramNameValStruct;
        if ~obj.MdlParametersMap.isKey(modelName)
            modelSimInput = Simulink.SimulationInput(modelName);
            origDirty = get_param(modelH,'Dirty');
            
            if obj.GetCoverage && ~any(modelH==obj.ModelHsNormalMode)
                % Referenced model is not in normal mode. You cannot
                % measure coverage in anyway. Turn off debugging on
                % Stateflow and MATLAB for Code Generation block
                currentParamNameValStruct.SFSimEnableDebug = 'off';
            end
            
            currenConfigSet = getActiveConfigSet(modelH);
            % Parameters will be changed remove the current ones
            Sldv.utils.replaceConfigSetRefWithCopy(modelH);
            
            % Change model parameters and store the existing ones
            [modelInfo, modelSimInput] = ...
                Sldv.SimModel.changeMdlParams(modelH, currentParamNameValStruct, modelSimInput);
            
            if strcmp(currentParamNameValStruct.SFSimEnableDebug,'on')
                % We are measuring coverage.
                % SFSimEnableDebug is turned on to measure coverage.
                % However, stop the sf debugger
                % Make sure that debugging is enabled on MATLAB for Code Generation blocks
                modelInfo = Sldv.SimModel.updateEMLSFSettings(modelH, modelInfo);
            end
            
            % OldConfigSet should be the last element in the struct filed list
            modelInfo.OldConfigSet = currenConfigSet;
            
            obj.MdlParametersMap(modelName) = modelInfo;
            
            obj.modelRefInputsMap(modelName) = modelSimInput;
            
            set_param(modelH,'Dirty',origDirty);
        end
    end
end
