Build matrix from an unknown number of parameters
Show older comments
Consider a model study which varies several different parameters, for example a study of building temperature in which parameters such as insulation value are varied. Each parameter's value is swept through a chosen range, resulting in a separate model run and output file for every possible combination of parameter values. From the output time series, metrics like the time averaged temperature can be calculated. To summarize the study, we want to store the average temperature vs. parameter choice in a matrix, but here's the problem: the number of parameters and their values differs every time the study is performed. One study might vary occupancy, insulation, and latitude; the next might vary number of windows and window glass type. Can you correct the following code so that it builds a summary matrix for an unknown number of parameters and their values?
% Parameters/values used in this study; not the same in subsequent studies
parameterList(1).name = 'occupancy' ;
parameterList(1).value = 0:10:100 ; % Percent of building occupied
parameterList(2).name = 'insulation' ;
parameterList(2).value = 1:6 ; % Insulation value
parameterList(3).name = 'latitude' ;
parameterList(3).value = 20:20:60 ; % Latitude of building site
fileList = dir('*.mat') ; % List of model output files; 198 for this study
function StudySummary = get_average_temperature(parameterList, fileList)
for iFile = 1:length(fileList)
% Each mat file contains the simulation's parameter values and output
load(fileList{iFile}) ;
% How to assign average temperature from this run to a summary matrix?
StudySummary.averageTemperature(iParameter1, iParameter2, ...) = ...
mean(temperatureTimeSeries) ;
end
Accepted Answer
More Answers (1)
Aaditya Kalsi
on 6 Jul 2012
I think what you're looking for is cells.
You can store up all values in a cell as:
a = rand(10);
b = ones(15);
c = 5;
paramVals = {a, b, c};
You can then use this to pass each one of the data values in each cell by:
f(a, b, c) can be replaced by f(paramVals{:})
1 Comment
Categories
Find more on Transmitters and Receivers in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!