How to sweep simulink parameters without using script or Sim command

6 views (last 30 days)
I have a simulink model that contains inputs from experimental data which i need to sweep for each simulation
In order to do so , i use matlab script contains a for loop that update input and sim command to simulate it.
This method is not helpful for me to use parameter estimator app
I want to sweep parameters in simulink without using matlab script (Sweep parameters using just simulink )
Is there any way ?
for i=1:length(Experimental-Data.S)
S = Experimental-Data.S(i);
T = Experimental-Data.T(i);
sim('PandO_MPPT_PeEbuilt_modified');

Answers (3)

Adarsh
Adarsh on 1 Apr 2025
I have previously used the parameter estimation for a Simulink model for multiple runs with “Parameter Estimation” app without any external MATLAB Script. I have followed the below flow:
For explaining let’s take a simple model for which parameters must be estimated:
Here let’s assume 2 runs must be made for estimation of parameters:
Input and Output Data for Experiment 1:
t (Time)= [1 2 3 4 5 6 7 8 9 … 100]
inp (Input port data)= [1 2 3 4 5 6 7 8 9 … 100]
out1 (Output for experiment 1) = inp.*4;
Input and Output Data for Experiment 2:
t (Time)= [1 2 3 4 5 6 7 8 9 … 100]
inp (Input port data)= [1 2 3 4 5 6 7 8 9 … 100]
out1 (Output for experiment 1) = inp.*8;
Now based on the two runs, the parameters "T" & "K" have to be estimated.
Steps to perform parameter estimation:
  • Open “Parameter Estimator” App
  • Click on “Add Experiment” two times to add two experiments named “Exp and “Exp_1”
  • Now in MATLAB command prompt initialize the variables “T” & “K” with “Simulink.Parameter” object and set the initial value to ‘1’
  • Now double click on “Exp” and select appropriate signal values from variables in workspace for the first run as shown below and also add ‘T’ as a parameter for this experiment and provide the set of values for ‘T’
  • Similarly repeat the previous step for “Exp_1”
  • Now go to the “PARAMETER ESTIMATION” tab in “Parameter Estimator” App and click on “Select Parameters” option and in the opened window add ‘K’ as a parameter under “Parameters Tuned for All Experiments” as shown below:
  • Now go to the “PARAMETER ESTIMATION” tab and then click on Estimation to perform the required parameter estimation and this converges to a solution as follows:
Here we have set ‘K’ as a single estimation variable across all runs and ‘T’ as individual estimation for Each Run, so we have 3 different variables in the plot which are:
  1. K
  2. T (for Exp)
  3. T (for Exp_1)
For more information on parameter estimation of multiple runs you can refer to the following documentation links:
  1. https://www.mathworks.com/help/releases/R2024b/sldo/ug/estimate-model-parameters-per-experiment-gui.html
  2. https://www.mathworks.com/help/releases/R2024b/sldo/gs/estimate-parameters-from-measured-data-using-the-gui.html
I hope it helps!

YASSER
YASSER on 1 Apr 2025
my case is slightly different from the one explained
in my case i do not perform parameter estimation in each iteration
rather, i collect outputs from iterations and than i do parameter estimation or curve fitting ..

Adarsh
Adarsh on 2 Apr 2025
I understand that you want to evaluate all the runs before proceeding with the parameter estimation. For this approach you can use the “For Each” subsystem in which you can paste your Simulink model and provide the input to the “For Each” subsystem using a “From Workspace” block and store its output of the “For Each” subsystem in the workspace using the “To Workspace” block. If each column in the input variable of the "From Workspace" block corresponds to data for a specific run, set the partition dimension to '1', in the properties section of the “For Each” block located in the “For Each” subsystem.
Here is a sample example that I have used for this approach:
Let’s say you have the data stored in the variable ‘u’ with each column representing the data for a particular run and ‘t’ represents the timestamps of data, then create a struct “simin” using:
simin = struct(time,t,signals,struct(values,u)) ;
Now, run the simulation and the results will be stored in workspace. You can use this data with the “Parameter Estimator” / “Curve Fitting” app for further analysis or estimation.
For more information on “For Each” subsystem and "ToWorkspace" and "FromWorkspace" blocks you can refer to the following documentation link:
  1. https://www.mathworks.com/help/releases/R2024b/simulink/slref/foreachsubsystem.html
  2. https://www.mathworks.com/help/releases/R2024b/simulink/slref/fromworkspace.html
  3. https://www.mathworks.com/help/releases/R2024b/simulink/slref/toworkspace.html
Hope it helps!

Categories

Find more on Programmatic Model Editing in Help Center and File Exchange

Products


Release

R2024b

Community Treasure Hunt

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

Start Hunting!