| 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 | eval([varargin{iarg} '=varargin{iarg+1};']);
|
|---|
| 98 | disp([varargin{iarg} '=' any2str(varargin{iarg+1}) ';']);
|
|---|
| 99 | else
|
|---|
| 100 | error(['''' any2str(varargin{iarg}) ''' is not a parameter name.']);
|
|---|
| 101 | end
|
|---|
| 102 | iarg=iarg+2;
|
|---|
| 103 | end
|
|---|
| 104 |
|
|---|
| 105 | %% draw the stacked bar plot
|
|---|
| 106 |
|
|---|
| 107 | % if there's only one row, Matlab 7.5 interprets it as a column,
|
|---|
| 108 | % so add an extra row, then reduce xlim
|
|---|
| 109 |
|
|---|
| 110 | if length(dresp) == 1
|
|---|
| 111 | cdfr=[cdfr; cdfr];
|
|---|
| 112 | end
|
|---|
| 113 |
|
|---|
| 114 | figure
|
|---|
| 115 | hl1=bar(cdfr,'stacked');
|
|---|
| 116 | % set barseries properties for lowest value
|
|---|
| 117 | whitebg('white')
|
|---|
| 118 | set(hl1(1),'FaceColor','white')
|
|---|
| 119 | set(hl1(1),'Visible','off')
|
|---|
| 120 |
|
|---|
| 121 | ax1=gca;
|
|---|
| 122 | if length(dresp) == 1
|
|---|
| 123 | set(ax1,'xlim',[0.5 1.5])
|
|---|
| 124 | end
|
|---|
| 125 |
|
|---|
| 126 | ylim('auto')
|
|---|
| 127 | [ylims]=ylim;
|
|---|
| 128 | if exist('ymin','var')
|
|---|
| 129 | ylims(1)=ymin;
|
|---|
| 130 | end
|
|---|
| 131 | if exist('ymax','var')
|
|---|
| 132 | ylims(2)=ymax;
|
|---|
| 133 | end
|
|---|
| 134 | ylim(ylims)
|
|---|
| 135 |
|
|---|
| 136 | set(ax1,'xtick',1:length(descr))
|
|---|
| 137 | set(ax1,'xticklabel',descr)
|
|---|
| 138 | if exist('xtlrot','var')
|
|---|
| 139 | htl=rotateticklabel(ax1,xtlrot);
|
|---|
| 140 | tlext=zeros(length(htl),4);
|
|---|
| 141 | for i=1:length(htl)
|
|---|
| 142 | tlext(i,:)=get(htl(i),'Extent');
|
|---|
| 143 | end
|
|---|
| 144 | end
|
|---|
| 145 |
|
|---|
| 146 | % add the annotation
|
|---|
| 147 |
|
|---|
| 148 | title('Response Levels for Specified Probabilities (PMA)')
|
|---|
| 149 | xlabel('Response');
|
|---|
| 150 | if exist('xtlrot','var')
|
|---|
| 151 | xlext=get(get(ax1,'xlabel'),'Extent');
|
|---|
| 152 | nskip=ceil(max(tlext(:,4))/xlext(4));
|
|---|
| 153 | xlabel(cellstr([repmat(' ',nskip,1);'Response']));
|
|---|
| 154 | clear nskip xlext tlext
|
|---|
| 155 | end
|
|---|
| 156 | ylabel('Response Level')
|
|---|
| 157 |
|
|---|
| 158 | if ~exist('lstr','var') || isempty(lstr)
|
|---|
| 159 | lstr=cell(1,max(lcdfr));
|
|---|
| 160 | for i=1:max(lcdfr)
|
|---|
| 161 | lstr(i)=cellstr(sprintf('%g%%',...
|
|---|
| 162 | 100*dresp(find(lcdfr == max(lcdfr),1,'first')).cdf(i,2)));
|
|---|
| 163 | end
|
|---|
| 164 | if ~isempty(find(lcdfr < max(lcdfr),1))
|
|---|
| 165 | warning('Variable number of probabilities for responses.');
|
|---|
| 166 | end
|
|---|
| 167 | end
|
|---|
| 168 |
|
|---|
| 169 | hleg1=legend(ax1,lstr,'Location','EastOutside',...
|
|---|
| 170 | 'Orientation','vertical','Interpreter','none');
|
|---|
| 171 |
|
|---|
| 172 | end
|
|---|