[1] | 1 | %
|
---|
[1013] | 2 | % plot a stacked bar chart of the response levels in the cdf.
|
---|
[1] | 3 | %
|
---|
[3092] | 4 | % []=plot_rlev_bars(dresp ,params)
|
---|
| 5 | % []=plot_rlev_bars(dresp,descr,params)
|
---|
[1] | 6 | %
|
---|
[1013] | 7 | % where the required input is:
|
---|
| 8 | % dresp (structure array, responses)
|
---|
[3092] | 9 | % or
|
---|
| 10 | % dresp (structure array, responses)
|
---|
| 11 | % descr (cell array, list of response descriptions desired)
|
---|
[1013] | 12 | %
|
---|
| 13 | % the required fields of dresp are:
|
---|
| 14 | % descriptor (char, description)
|
---|
| 15 | % cdf(:,4) (double matrix, CDF table)
|
---|
| 16 | %
|
---|
[3092] | 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 | %
|
---|
[1013] | 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
|
---|
[3092] | 40 | % of Technology. (J. Schiermeier, NTR 47078)
|
---|
[1013] | 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 | %
|
---|
[3092] | 49 | function []=plot_rlev_bars(varargin)
|
---|
[1] | 50 |
|
---|
| 51 | if ~nargin
|
---|
| 52 | help plot_rlev_bars
|
---|
| 53 | return
|
---|
| 54 | end
|
---|
| 55 |
|
---|
[3092] | 56 | %% process input data and assemble into matrices and increments
|
---|
[1] | 57 |
|
---|
[3092] | 58 | % responses
|
---|
[1] | 59 |
|
---|
[3092] | 60 | iarg=1;
|
---|
| 61 | if isstruct(varargin{iarg})
|
---|
| 62 | dresp=varargin{iarg};
|
---|
| 63 | iarg=iarg+1;
|
---|
[13975] | 64 |
|
---|
[3092] | 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
|
---|
[13975] | 70 |
|
---|
[3092] | 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
|
---|
[1] | 86 | end
|
---|
| 87 | end
|
---|
| 88 | end
|
---|
[3092] | 89 | else
|
---|
| 90 | error(['''' inputname(iarg) ''' is not a structure.']);
|
---|
[1] | 91 | end
|
---|
| 92 |
|
---|
[3092] | 93 | % parameters
|
---|
| 94 |
|
---|
| 95 | while (iarg <= nargin-1)
|
---|
| 96 | if ischar(varargin{iarg})
|
---|
[7398] | 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
|
---|
[3092] | 105 | else
|
---|
| 106 | error(['''' any2str(varargin{iarg}) ''' is not a parameter name.']);
|
---|
| 107 | end
|
---|
| 108 | iarg=iarg+2;
|
---|
| 109 | end
|
---|
| 110 |
|
---|
[1] | 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 |
|
---|
[1013] | 116 | if length(dresp) == 1
|
---|
[3092] | 117 | cdfr=[cdfr; cdfr];
|
---|
[1] | 118 | end
|
---|
| 119 |
|
---|
[3092] | 120 | figure
|
---|
| 121 | hl1=bar(cdfr,'stacked');
|
---|
[1] | 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;
|
---|
[1013] | 128 | if length(dresp) == 1
|
---|
[1] | 129 | set(ax1,'xlim',[0.5 1.5])
|
---|
| 130 | end
|
---|
| 131 |
|
---|
[3092] | 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 |
|
---|
[1] | 152 | % add the annotation
|
---|
| 153 |
|
---|
[1013] | 154 | title('Response Levels for Specified Probabilities (PMA)')
|
---|
[3092] | 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
|
---|
[1] | 162 | ylabel('Response Level')
|
---|
| 163 |
|
---|
| 164 | if ~exist('lstr','var') || isempty(lstr)
|
---|
[3092] | 165 | lstr=cell(1,max(lcdfr));
|
---|
| 166 | for i=1:max(lcdfr)
|
---|
[1] | 167 | lstr(i)=cellstr(sprintf('%g%%',...
|
---|
[3092] | 168 | 100*dresp(find(lcdfr == max(lcdfr),1,'first')).cdf(i,2)));
|
---|
[1] | 169 | end
|
---|
[3092] | 170 | if ~isempty(find(lcdfr < max(lcdfr),1))
|
---|
[1013] | 171 | warning('Variable number of probabilities for responses.');
|
---|
[1] | 172 | end
|
---|
| 173 | end
|
---|
| 174 |
|
---|
| 175 | hleg1=legend(ax1,lstr,'Location','EastOutside',...
|
---|
| 176 | 'Orientation','vertical','Interpreter','none');
|
---|
| 177 |
|
---|
| 178 | end
|
---|