1 | %
|
---|
2 | % plot a stacked bar chart of the response levels in the cdf.
|
---|
3 | %
|
---|
4 | % []=plot_rlev_bars(dresp ,params)
|
---|
5 | % []=plot_rlev_bars(dresp,descr,params)
|
---|
6 | %
|
---|
7 | % where the required input is:
|
---|
8 | % dresp (structure array, responses)
|
---|
9 | % or
|
---|
10 | % dresp (structure array, responses)
|
---|
11 | % descr (cell array, list of response descriptions desired)
|
---|
12 | %
|
---|
13 | % the required fields of dresp are:
|
---|
14 | % descriptor (char, description)
|
---|
15 | % cdf(:,4) (double matrix, CDF table)
|
---|
16 | %
|
---|
17 | % the optional input is:
|
---|
18 | % params (string/numeric, parameter names and values)
|
---|
19 | %
|
---|
20 | % where the optional parameters are:
|
---|
21 | % ymin (numeric, minimum of y-axis)
|
---|
22 | % ymax (numeric, maximum of y-axis)
|
---|
23 | % xtlrot (numeric, rotation in degrees of x-tick labels)
|
---|
24 | % lstr (cell array, legend labels)
|
---|
25 | %
|
---|
26 | % for each response in the input array, this function plots
|
---|
27 | % a stacked bar plot of the responses, where the bars are
|
---|
28 | % stacked by the response levels corresponding to the given
|
---|
29 | % probabilities in the CDF, and annotates it with the
|
---|
30 | % description. the legend labels can be given or constructed
|
---|
31 | % from the probabilities.
|
---|
32 | %
|
---|
33 | % this data would typically be contained in the dakota output
|
---|
34 | % file and read by dakota_out_parse.
|
---|
35 | %
|
---|
36 | % "Copyright 2009, by the California Institute of Technology.
|
---|
37 | % ALL RIGHTS RESERVED. United States Government Sponsorship
|
---|
38 | % acknowledged. Any commercial use must be negotiated with
|
---|
39 | % the Office of Technology Transfer at the California Institute
|
---|
40 | % of Technology. (J. Schiermeier, NTR 47078)
|
---|
41 | %
|
---|
42 | % This software may be subject to U.S. export control laws.
|
---|
43 | % By accepting this software, the user agrees to comply with
|
---|
44 | % all applicable U.S. export laws and regulations. User has the
|
---|
45 | % responsibility to obtain export licenses, or other export
|
---|
46 | % authority as may be required before exporting such information
|
---|
47 | % to foreign countries or providing access to foreign persons."
|
---|
48 | %
|
---|
49 | function []=plot_rlev_bars(varargin)
|
---|
50 |
|
---|
51 | if ~nargin
|
---|
52 | help plot_rlev_bars
|
---|
53 | return
|
---|
54 | end
|
---|
55 |
|
---|
56 | %% process input data and assemble into matrices and increments
|
---|
57 |
|
---|
58 | % responses
|
---|
59 |
|
---|
60 | iarg=1;
|
---|
61 | if isstruct(varargin{iarg})
|
---|
62 | dresp=varargin{iarg};
|
---|
63 | iarg=iarg+1;
|
---|
64 |
|
---|
65 | % if iarg <= nargin && (iscell(varargin{iarg}) || ischar(varargin{iarg}))
|
---|
66 | if iarg <= nargin && iscell(varargin{iarg})
|
---|
67 | dresp=struc_desc(dresp,varargin{iarg});
|
---|
68 | iarg=iarg+1;
|
---|
69 | end
|
---|
70 |
|
---|
71 | descr=cell (1,length(dresp));
|
---|
72 | lcdfr=zeros(1,length(dresp));
|
---|
73 | for i=1:length(dresp)
|
---|
74 | lcdfr(i)=size(dresp(i).cdf,1);
|
---|
75 | end
|
---|
76 | cdfr=zeros(length(dresp),max(lcdfr));
|
---|
77 |
|
---|
78 | for i=1:length(dresp)
|
---|
79 | descr(i)=cellstr(dresp(i).descriptor);
|
---|
80 | if ~isempty(dresp(i).cdf)
|
---|
81 | cdfr(i,1)=dresp(i).cdf(1,1);
|
---|
82 | for j=2:size(dresp(i).cdf,1)
|
---|
83 | if (dresp(i).cdf(j,1) > dresp(i).cdf(j-1,1))
|
---|
84 | cdfr(i,j)=dresp(i).cdf(j,1)-dresp(i).cdf(j-1,1);
|
---|
85 | end
|
---|
86 | end
|
---|
87 | end
|
---|
88 | end
|
---|
89 | else
|
---|
90 | error(['''' inputname(iarg) ''' is not a structure.']);
|
---|
91 | end
|
---|
92 |
|
---|
93 | % parameters
|
---|
94 |
|
---|
95 | while (iarg <= nargin-1)
|
---|
96 | if ischar(varargin{iarg})
|
---|
97 | if ~isempty(strmatch(varargin{iarg},...
|
---|
98 | {'ymin','ymax','xtlrot','lstr'},...
|
---|
99 | 'exact'))
|
---|
100 | eval([varargin{iarg} '=varargin{iarg+1};']);
|
---|
101 | disp([varargin{iarg} '=' any2str(varargin{iarg+1}) ';']);
|
---|
102 | else
|
---|
103 | warning([varargin{iarg} '=' any2str(varargin{iarg+1}) ' is not recognized.']);
|
---|
104 | end
|
---|
105 | else
|
---|
106 | error(['''' any2str(varargin{iarg}) ''' is not a parameter name.']);
|
---|
107 | end
|
---|
108 | iarg=iarg+2;
|
---|
109 | end
|
---|
110 |
|
---|
111 | %% draw the stacked bar plot
|
---|
112 |
|
---|
113 | % if there's only one row, Matlab 7.5 interprets it as a column,
|
---|
114 | % so add an extra row, then reduce xlim
|
---|
115 |
|
---|
116 | if length(dresp) == 1
|
---|
117 | cdfr=[cdfr; cdfr];
|
---|
118 | end
|
---|
119 |
|
---|
120 | figure
|
---|
121 | hl1=bar(cdfr,'stacked');
|
---|
122 | % set barseries properties for lowest value
|
---|
123 | whitebg('white')
|
---|
124 | set(hl1(1),'FaceColor','white')
|
---|
125 | set(hl1(1),'Visible','off')
|
---|
126 |
|
---|
127 | ax1=gca;
|
---|
128 | if length(dresp) == 1
|
---|
129 | set(ax1,'xlim',[0.5 1.5])
|
---|
130 | end
|
---|
131 |
|
---|
132 | ylim('auto')
|
---|
133 | [ylims]=ylim;
|
---|
134 | if exist('ymin','var')
|
---|
135 | ylims(1)=ymin;
|
---|
136 | end
|
---|
137 | if exist('ymax','var')
|
---|
138 | ylims(2)=ymax;
|
---|
139 | end
|
---|
140 | ylim(ylims)
|
---|
141 |
|
---|
142 | set(ax1,'xtick',1:length(descr))
|
---|
143 | set(ax1,'xticklabel',descr)
|
---|
144 | if exist('xtlrot','var')
|
---|
145 | htl=rotateticklabel(ax1,xtlrot);
|
---|
146 | tlext=zeros(length(htl),4);
|
---|
147 | for i=1:length(htl)
|
---|
148 | tlext(i,:)=get(htl(i),'Extent');
|
---|
149 | end
|
---|
150 | end
|
---|
151 |
|
---|
152 | % add the annotation
|
---|
153 |
|
---|
154 | title('Response Levels for Specified Probabilities (PMA)')
|
---|
155 | xlabel('Response');
|
---|
156 | if exist('xtlrot','var')
|
---|
157 | xlext=get(get(ax1,'xlabel'),'Extent');
|
---|
158 | nskip=ceil(max(tlext(:,4))/xlext(4));
|
---|
159 | xlabel(cellstr([repmat(' ',nskip,1);'Response']));
|
---|
160 | clear nskip xlext tlext
|
---|
161 | end
|
---|
162 | ylabel('Response Level')
|
---|
163 |
|
---|
164 | if ~exist('lstr','var') || isempty(lstr)
|
---|
165 | lstr=cell(1,max(lcdfr));
|
---|
166 | for i=1:max(lcdfr)
|
---|
167 | lstr(i)=cellstr(sprintf('%g%%',...
|
---|
168 | 100*dresp(find(lcdfr == max(lcdfr),1,'first')).cdf(i,2)));
|
---|
169 | end
|
---|
170 | if ~isempty(find(lcdfr < max(lcdfr),1))
|
---|
171 | warning('Variable number of probabilities for responses.');
|
---|
172 | end
|
---|
173 | end
|
---|
174 |
|
---|
175 | hleg1=legend(ax1,lstr,'Location','EastOutside',...
|
---|
176 | 'Orientation','vertical','Interpreter','none');
|
---|
177 |
|
---|
178 | end
|
---|