Initialising a Simulink model workspace from MATLAB file – how to determine the parent model?
Hi everybody,
I’ve recently learnt how to make use of the Simulink model worksapce, to keep large numbers of parameters separate from the base workspace. Specifically, I am using a "MATLAB file" (Initialise.m) as the data source, which loads a lot of data used only by this model. However, I find myself interacting with this model in 2 different ways:
When developing the model it is convenient to simply run Initialise.m from the command window, and open the model manually, allowing me to click the run button and interact immediately with the outputs. For this reason the model is always saved with the DataSource set to "model file", so it does not take ages to open.
When using the model in anger it is run within a parfor loop using the sim command, allowing parameter sweeps to be performed. Within this parfor, the data source therefore gets set to Initialise.m, before reinitialising the model using the code below. Finally the model is closed without saving, so it can always be opened quickly, allowing it to be used in way above.
mdlWks.DataSource = ‘MATLAB File’;
mdlWks.FileName = ‘Initialise.m’;
mdlWks.reload
MY QUESTION IS within Initialise.m, is it possible to determine which of the 2 methods is being used? i.e. when that function is being run as part of a model initialisation? This will allow me to set some certain parameters in the correct way, either to some default values (for method 1), or based on the parameter sweeps (for method 2).
Many thanks for any help!
LeeHi everybody,
I’ve recently learnt how to make use of the Simulink model worksapce, to keep large numbers of parameters separate from the base workspace. Specifically, I am using a "MATLAB file" (Initialise.m) as the data source, which loads a lot of data used only by this model. However, I find myself interacting with this model in 2 different ways:
When developing the model it is convenient to simply run Initialise.m from the command window, and open the model manually, allowing me to click the run button and interact immediately with the outputs. For this reason the model is always saved with the DataSource set to "model file", so it does not take ages to open.
When using the model in anger it is run within a parfor loop using the sim command, allowing parameter sweeps to be performed. Within this parfor, the data source therefore gets set to Initialise.m, before reinitialising the model using the code below. Finally the model is closed without saving, so it can always be opened quickly, allowing it to be used in way above.
mdlWks.DataSource = ‘MATLAB File’;
mdlWks.FileName = ‘Initialise.m’;
mdlWks.reload
MY QUESTION IS within Initialise.m, is it possible to determine which of the 2 methods is being used? i.e. when that function is being run as part of a model initialisation? This will allow me to set some certain parameters in the correct way, either to some default values (for method 1), or based on the parameter sweeps (for method 2).
Many thanks for any help!
Lee Hi everybody,
I’ve recently learnt how to make use of the Simulink model worksapce, to keep large numbers of parameters separate from the base workspace. Specifically, I am using a "MATLAB file" (Initialise.m) as the data source, which loads a lot of data used only by this model. However, I find myself interacting with this model in 2 different ways:
When developing the model it is convenient to simply run Initialise.m from the command window, and open the model manually, allowing me to click the run button and interact immediately with the outputs. For this reason the model is always saved with the DataSource set to "model file", so it does not take ages to open.
When using the model in anger it is run within a parfor loop using the sim command, allowing parameter sweeps to be performed. Within this parfor, the data source therefore gets set to Initialise.m, before reinitialising the model using the code below. Finally the model is closed without saving, so it can always be opened quickly, allowing it to be used in way above.
mdlWks.DataSource = ‘MATLAB File’;
mdlWks.FileName = ‘Initialise.m’;
mdlWks.reload
MY QUESTION IS within Initialise.m, is it possible to determine which of the 2 methods is being used? i.e. when that function is being run as part of a model initialisation? This will allow me to set some certain parameters in the correct way, either to some default values (for method 1), or based on the parameter sweeps (for method 2).
Many thanks for any help!
Lee simulink, model workspace, reinitialize from source, initialize model MATLAB Answers — New Questions