Build matrix from an unknown number of parameters

1 次查看(过去 30 天)
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

采纳的回答

Walter Roberson
Walter Roberson 2012-7-6
Is it necessary to do the search based upon parameter values? As in the user gives a query "tell me the information for occupancy 50, insulation 4, latitude 40" ? Or is the summary to include all available information?
If you are building a summary of all available information, then just use indexing, such as
averageTemperature{6, 4, 2}
You can prepare these indices ahead of time without the retrieval needing to know how many there are:
idx = [6, 4, 2];
cellidx = num2cell(idx);
averageTemperature{ cellidx{:} }
If you are working off of a query then you need to worry about the query values not exactly matching the known parameter values. You need to find the nearest known parameter value. Such as
paramidx = interp1( paramvalues{1}, 1:length(paramvalues{1}), QueryValue, 'nearest');
and repeat that for each query parameter to arrive at the idx array that you plug into the scheme above.
  3 个评论
K E
K E 2012-7-9
Thanks for your patience with these questions. This will be very helpful to me.

请先登录,再进行评论。

更多回答(1 个)

Aaditya Kalsi
Aaditya Kalsi 2012-7-6
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 个评论
K E
K E 2012-7-6
编辑:K E 2012-7-6
I am not familiar with cell arrays of numbers: In the following example, how would I access the average temperature associated with the case where occupancy=50 (first cell), insulation=4 (second cell), and latitude=40 (third cell)? I need to store the averageTemperature of every combination of parameter values. Here there are 11*6*3=198 combinations; next study will have a different number of combinations, say 5*2*3*7*6.
% Value ranges for occupancy, insulation, and latitude respectively
paramVals = { 0:10:100, 1:6, 20:20:60 } ;
% Preallocate cell that will store the average temperature
% for each combination of parameter values
averageTemperature = cell(size(paramVals)) ;

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by