Main Content

Import Command-Line Objects into Parameter Estimator Programmatically

This example shows how to create objects through the command-line functionality and import them into the Parameter Estimator app using sdo.SessionInterface.

You can set up a parameter estimation problem in the Parameter Estimator app by following the UI workflow. Sometimes, when you want to specify a large number of experiments and their measured data or specify a large number of parameters to be estimated along with their minimum and maximum values, this process becomes tedious. You can specify the parameters and experiments using the command-line functionality instead. Then, you can import the parameters and experiments into the Parameter Estimator app using sdo.SessionInterface.

Initiate Problem Specification in the App

Open the Simulink® model.

open_system('spe_muscle')

Muscle Reflex Model

To open a new Parameter Estimator app session for the model, in the Apps tab, click Parameter Estimator, or enter this command at the MATLAB® command line.

spetool('spe_muscle')

Define one experiment and one parameter to be estimated in the app. These appear in the Experiments and Parameters sections of the app, respectively.

  • To define experiments, in the Parameter Estimation tab, click New Experiment. For further details on specifying experiments, see Specify Estimation Data.

  • To define a parameter to be estimated, in the Parameter Estimation tab, click Select Parameters. For further details on specifying parameters, see Specify Parameters for Estimation.

App_OneParam_OneExper.png

When there are many additional experiments to specify and many other parameters to be estimated, specifying all of them directly in the app can be tedious. Instead, you can define them in the command line and import them into the app.

To get an idea on how to create parameter and experiment objects in the command line, in the Parameter Estimation tab, in the Estimate menu, click Generate MATLAB Function.

Define Parameters in Command Line

Create a blank session sdo.SessionInterface object to interface with both the app and the objects defined in the command line.

si = sdo.SessionInterface('spe_muscle','ParameterEstimation')
si = 
  SessionInterface with properties:

            ModelName: 'spe_muscle'
              AppType: 'ParameterEstimation'
           Parameters: []
          Experiments: [0×1 sdo.Experiment]
    EstimationOptions: [1×1 sdo.OptimizeOptions]

Define all the model parameters to be estimated in the command line as a vector of param.Continuous objects. Because one of the parameters, tau, is a time constant, specify that it cannot be negative.

params = [...
    param.Continuous('alpha',0.2) ; ...
    param.Continuous('beta',0.1) ; ...
    param.Continuous('tau',0.005)];
params(3).Minimum = 0;

Assign the defined parameters to the Parameters property of the session interface object.

si.Parameters = params;

Define Experiments in Command Line

Define experiments in the command line using sdo.Experiment and Simulink.SimulationData.Signal. To define multiple experiments, use a for loop.

load('muscle_Data.mat','time','data1','data2','data3','data4');

dataList = {data1 data2 data3 data4};
Exper = [];
for ct = 1:numel(dataList)
    data = dataList{ct};
    oneExper = sdo.Experiment('spe_muscle');
    outputInfo = Simulink.SimulationData.Signal;
    outputInfo.Values = timeseries(data,time);
    outputInfo.BlockPath = 'spe_muscle/Integrator';
    outputInfo.PortType = 'outport';
    outputInfo.PortIndex = 1;
    outputInfo.Name = 'theta';
    oneExper.OutputData = outputInfo;

    Exper = [Exper;oneExper];
end

Assign the defined experiments to the Experiments property of the session interface object.

si.Experiments = Exper;

Plot the experiment data.

clf;
hold('on');
for ct = 1:numel(Exper)
    plot(Exper(ct).OutputData.Values, ...
        'DisplayName', "Measured Data " + num2str(ct));
end
legend('show');

Figure contains an axes object. The axes object contains 4 objects of type line. These objects represent Measured Data 1, Measured Data 2, Measured Data 3, Measured Data 4.

Import Command-Line Objects into the App

Import the objects defined in the command line into the app using sdotool. This action launches the app.

sdotool(si);

You can see that the app is populated with all the parameters to be estimated and the experiments with measured data.

App_AfterUsingInterface.png

Close the model.

bdclose('spe_muscle')

See Also

| |

Topics

See Also

Topics