Calculations/MOT Capture Process Simulation/@MOTSimulator/doOneParameterScan.m

67 lines
3.1 KiB
Mathematica
Raw Normal View History

function [LoadingRateArray, StandardErrorArray, ConfidenceIntervalArray] = doOneParameterScan(this, ParameterName, ParameterArray, varargin)
p = inputParser;
p.KeepUnmatched = true;
addRequired(p, 'ClassObject' , @isobject);
addRequired(p, 'ParameterName' , @ischar);
addRequired(p, 'ParameterArray' , @isvector);
addParameter(p, 'ChangeRelatedParameter', false, @islogical);
addParameter(p, 'RelatedParameterName', 'none', @ischar);
addParameter(p, 'RelatedParameterArray', length(ParameterArray), @isvector);
addParameter(p, 'ChangeInitialConditions', false, @islogical);
addParameter(p, 'ParameterNameArray', {}, @iscell);
addParameter(p, 'ParameterValueArray', {}, @iscell);
p.parse(this, ParameterName, ParameterArray, varargin{:})
ParameterName = p.Results.ParameterName;
ParameterArray = p.Results.ParameterArray;
ChangeRelatedParameter = p.Results.ChangeRelatedParameter;
RelatedParameterName = p.Results.RelatedParameterName;
RelatedParameterArray = p.Results.RelatedParameterArray;
ChangeInitialConditions = p.Results.ChangeInitialConditions;
ParameterNameArray = p.Results.ParameterNameArray;
ParameterValueArray = p.Results.ParameterValueArray;
NumberOfPointsForParam = length(ParameterArray);
LoadingRateArray = zeros(1,NumberOfPointsForParam);
StandardErrorArray = zeros(1,NumberOfPointsForParam);
ConfidenceIntervalArray = zeros(NumberOfPointsForParam, 2);
for i=1:NumberOfPointsForParam
eval(sprintf('OptionsStruct.%s = %d;', ParameterName, ParameterArray(i)));
if ChangeRelatedParameter
eval(sprintf('OptionsStruct.%s = %d;', RelatedParameterName, RelatedParameterArray(i)));
end
if ChangeInitialConditions
for j = 1:length(ParameterNameArray)
eval(sprintf('OptionsStruct.%s = %d;', ParameterNameArray{j}, ParameterValueArray{j}));
end
end
options = Helper.convertstruct2cell(OptionsStruct);
this.setInitialConditions(options{:});
tic
[LoadingRate, StandardError, ConfidenceInterval] = this.runSimulation();
LoadingRateArray(i) = LoadingRate;
StandardErrorArray(i) = StandardError;
ConfidenceIntervalArray(i,1) = ConfidenceInterval(1);
ConfidenceIntervalArray(i,2) = ConfidenceInterval(2);
end
if this.DoSave
LoadingRate = struct;
LoadingRate.Values = LoadingRateArray;
LoadingRate.Errors = StandardErrorArray;
LoadingRate.CI = ConfidenceIntervalArray;
this.Results = LoadingRate;
SaveFolder = [this.SaveDirectory filesep 'Results'];
Filename = ['OneParameterScan_' datestr(now,'yyyymmdd_HHMM')];
eval([sprintf('%s_Object', Filename) ' = this;']);
mkdir(SaveFolder);
save([SaveFolder filesep Filename], sprintf('%s_Object', Filename));
end
end