Skip to content

Commit 7851ec0

Browse files
committed
implemented a sanity check, to avoid failure of plotting routines if number or name of parameters or properties is not set
1 parent 4d12ee9 commit 7851ec0

File tree

7 files changed

+85
-0
lines changed

7 files changed

+85
-0
lines changed

plotConfidenceIntervals.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@
8888
pIndexSet = allOptions.parameter_index;
8989
end
9090
end
91+
92+
% Check, if pStruct has all necessary fieds
93+
pStruct = checkSanityOfStructs(pStruct, ['p' type(2:end)]);
94+
9195
numP = length(pIndexSet);
9296
iMAP = allOptions.MAP_index;
9397
if isempty(iMAP)

plotMCMCdiagnosis.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
% * 2016/10/10 Daniel Weindl
3131

3232
%% Check and assign inputs
33+
34+
% Check, if parameters has all necessary fieds
35+
parameters = checkSanityOfStructs(parameters, 'parameters');
36+
3337
% Plot type
3438
type = 'parameters';
3539
if nargin >= 2 && ~isempty(varargin{1})

plotMultiStarts.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
% * 2016/10/07 Daniel Weindl
2929

3030
%% CHECK AND ASSIGN INPUTS
31+
32+
% Check, if parameters has all necessary fieds
33+
parameters = checkSanityOfStructs(parameters, 'parameters');
34+
3135
% Open figure
3236
if length(varargin) >= 1 && ~isempty(varargin{1}) && isvalid(varargin{1})
3337
fh = figure(varargin{1});

plotParameterUncertainty.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@
5858
end
5959
end
6060

61+
% Check, if parameters has all necessary fieds
62+
parameters = checkSanityOfStructs(parameters, 'parameters');
63+
6164
% Open figure
6265
if length(varargin) >= 2 && ~isempty(varargin{2})
6366
fh = figure(varargin{2});

plotPropertyMultiStarts.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
fh = figure('Name','plotPropertyMultiStarts');
2929
end
3030

31+
% Check, if properties has all necessary fieds
32+
properties = checkSanityOfStructs(properties, 'properties');
33+
3134
% Options
3235
if length(varargin) >= 2
3336
options = handlePlottingOptionArgument(varargin{2});

plotPropertyUncertainty.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
end
3737
end
3838

39+
% Check, if properties has all necessary fieds
40+
properties = checkSanityOfStructs(properties, 'properties');
41+
3942
% Open figure
4043
if length(varargin) >= 2 && ~isempty(varargin{2})
4144
fh = figure(varargin{2});

private/checkSanityOfStructs.m

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
function pStruct = checkSanityOfStructs(pStruct, type)
2+
% checkSanityOfStructs.m checks if the necessary fields of the parameters
3+
% or the properties struct are set. If necessary fields are missing but can
4+
% unambiguously, this will be done. Otherwise, an error will be displayed.
5+
%
6+
% USAGE:
7+
% pStruct = checkSanityOfStructs(pStruct, type)
8+
%
9+
% Parameters:
10+
% pStruct: parameters or properties struct.
11+
% type: string, either 'parameters' or 'properties'
12+
%
13+
% Return values:
14+
% pSturct: struct containing informations about the parameters or the
15+
% properties
16+
%
17+
% History:
18+
% * 2017/05/21 Paul Stapor
19+
20+
21+
22+
% See which struct should be checked
23+
if ~(strcmp(type, 'parameters') || strcmp(type, 'properties'))
24+
error('The given type of struct is invalid. Only parameters and properties and be checked by this function.');
25+
else
26+
if strcmp(type, 'parameters')
27+
short_type = 'par';
28+
else
29+
short_type = 'prop';
30+
end
31+
end
32+
33+
% The least necessary information are lower and upper bounds for parameters
34+
if ~isfield(pStruct, 'min')
35+
error(['The struct ' type ' has no lower bounds provided.']);
36+
end
37+
if ~isfield(pStruct, 'max')
38+
error(['The struct ' type ' has no upper bounds provided.']);
39+
end
40+
41+
% Upper and lower bounds need to have the same length
42+
if ~all(size(pStruct.min) == size(pStruct.max))
43+
error(['The vectors for the lower and upper bounds of' type ' do not have the same size.']);
44+
end
45+
46+
% The number of pStruct needs to be set accordingly
47+
if ~isfield(pStruct, 'number')
48+
pStruct.number = length(pStruct.min);
49+
else
50+
if (length(pStruct.min) ~= pStruct.number)
51+
warning(['The size of struct ' type ' was set incorrectly in ' type '.number. This was corrected.']);
52+
end
53+
end
54+
55+
% The names of the parameters have to be set correctly
56+
if ~isfield(pStruct, 'name')
57+
pStruct.name = arrayfun(@(x) [short_type num2str(x)], 1:pStruct.number, 'UniformOutput', false);
58+
else
59+
if (length(pStruct.name) ~= pStruct.number)
60+
error(['The names for the struct ' type ' did not have the correct length. Either provide them with correct length or leave ' type '.name empty.']);
61+
end
62+
end
63+
64+
end

0 commit comments

Comments
 (0)