Main Content

reload

Reinitialize variables from the data source of a model workspace

Description

reload(mdlWks) reinitializes the variables in the model workspace represented by the Simulink.ModelWorkspace object mdlWks. When you set the DataSource property of the model workspace to 'MAT-File', 'MATLAB File', or 'MATLAB Code', reload overwrites variables that exist in the model workspace by loading the associated MAT-file or by running the associated MATLAB code.

example

Examples

collapse all

Open the example model vdp.

openExample('simulink_general/VanDerPolOscillatorExample')

Create a Simulink.ModelWorkspace object that represents the model workspace of vdp.

mdlWks = get_param('vdp','ModelWorkspace');

Configure the model workspace to use some MATLAB code as a data source.

mdlWks.DataSource = 'MATLAB Code';
mdlWks.MATLABCode = sprintf('myVar = 5.12;\nmyOtherVar = 7.22;');

Create variables in the model workspace by executing the MATLAB code.

reload(mdlWks)

Assign new values to the variables in the model workspace.

assignin(mdlWks,'myVar',5.22)
assignin(mdlWks,'myOtherVar',7.33)

Overwrite the new values with the values specified by the MATLAB code.

reload(mdlWks)

Confirm that the variables have the values specified by the MATLAB code.

myVarValue = getVariable(mdlWks,'myVar')
myOtherVarValue = getVariable(mdlWks,'myOtherVar')
myVarValue =

    5.1200


myOtherVarValue =

    7.2200

Input Arguments

collapse all

Target model workspace, specified as a Simulink.ModelWorkspace object.

Version History

Introduced before R2006a