Using 'parsim' with a group of parameters
조회 수: 5 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
Vijeta
2023년 6월 15일
편집: Vijeta
2023년 6월 15일
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Run Multiple Simulations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!