Borrar filtros
Borrar filtros

Using 'parsim' with a group of parameters

3 visualizaciones (últimos 30 días)
Paola Martin
Paola Martin el 23 de Mayo de 2023
Editada: Vijeta el 15 de Jun. de 2023
Good afternon, i have 3 tables with a set of parameters (each table has a different number of parameters) that I want to simulate in parallel with the parsim command. I have managed to extract the data and create the groups to simulate but at the moment of using parsim, either all the commands do not appear or they appear mixed.
I still don't seem to fully understand how to use the commands to simulate in parallel.
The parameters are fixed, i.e. they are not a range.
Thanks in advance

Respuestas (1)

Vijeta
Vijeta el 15 de Jun. de 2023
Editada: Vijeta el 15 de Jun. de 2023
Hi,
Here's an example of how you can use `parsim` to simulate different sets of parameters in parallel using MATLAB.
Assuming you have three tables of parameters, `table1`, `table2`, and `table3`, each with a different number of parameters and the function you want to evaluate for each set of parameters is `myFunction`:
% Initialize tables of parameters
table1 = readtable('table1.csv');
table2 = readtable('table2.csv');
table3 = readtable('table3.csv');
% Combine tables into a cell array of tables
paramTables = {table1, table2, table3};
% Define the number of simulations to run
numSims = length(paramTables);
% Initialize results variable
results = cell(numSims, 1);
% Create parallel pool
parpool();
% Evaluate function for each set of parameters in parallel
parfor i = 1:numSims
results{i} = myFunction(paramTables{i}, otherInputs);
end
% Close parallel pool
delete(gcp);
In this example, the `readtable` functions load data from CSV files into MATLAB tables. These tables are then combined into a cell array called `paramTables` which serves as input to the `parsim` function.
The `parfor` loop evaluates the `myFunction` function for each set of parameters in parallel, where `otherInputs` is a variable containing any additional inputs required by the function.
The results are stored in a cell array called `results`. Note that the results are stored as a cell array because each set of parameters may have a different number of output variables or different sizes of output variables.
Finally, the parallel pool is closed with the `delete(gcp)` command.

Categorías

Más información sobre Run Multiple Simulations en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by