| 1 | % | 
|---|
| 2 | %  plot line plots of responses vs. variables. | 
|---|
| 3 | % | 
|---|
| 4 | %  []=plot_rvsv_line(dvar       ,dresp      ,params) | 
|---|
| 5 | %  []=plot_rvsv_line(dvar ,descv,dresp,descr,params) | 
|---|
| 6 | %  []=plot_rvsv_line(sampv,descv,sampr,descr,params) | 
|---|
| 7 | % | 
|---|
| 8 | %  where the required input is: | 
|---|
| 9 | %    dvar          (structure array, variables) | 
|---|
| 10 | %      or | 
|---|
| 11 | %    dvar          (structure array, variables) | 
|---|
| 12 | %    descv         (cell array, list of variable descriptions desired) | 
|---|
| 13 | %      or | 
|---|
| 14 | %    sampv         (double array, lists of variable samples) | 
|---|
| 15 | %    descv         (cell array, list of variable descriptions) | 
|---|
| 16 | % | 
|---|
| 17 | %    dresp         (structure array, responses) | 
|---|
| 18 | %      or | 
|---|
| 19 | %    dresp         (structure array, responses) | 
|---|
| 20 | %    descr         (cell array, list of response descriptions desired) | 
|---|
| 21 | %      or | 
|---|
| 22 | %    sampr         (double array, lists of response samples) | 
|---|
| 23 | %    descr         (cell array, list of response descriptions) | 
|---|
| 24 | % | 
|---|
| 25 | %  the required fields of dvar and dresp are: | 
|---|
| 26 | %    descriptor    (char, description) | 
|---|
| 27 | %    sample        (double vector, list of samples) | 
|---|
| 28 | % | 
|---|
| 29 | %  the optional input is: | 
|---|
| 30 | %    params        (string/numeric, parameter names and values) | 
|---|
| 31 | % | 
|---|
| 32 | %  where the optional parameters are: | 
|---|
| 33 | %    nplotr        (numeric, number of plot rows) | 
|---|
| 34 | %    nplotc        (numeric, number of plot columns) | 
|---|
| 35 | %    ymin          (numeric, minimum of y-axis) | 
|---|
| 36 | %    ymax          (numeric, maximum of y-axis) | 
|---|
| 37 | %    yscat         (char, 'off' to turn off y-axis scattergram) | 
|---|
| 38 | % | 
|---|
| 39 | %  for each variable/response combination in the input array, this | 
|---|
| 40 | %  function plots a line plot.  all of the variables and responses | 
|---|
| 41 | %  are plotted on the same axes, if nplotr and nplotc are not | 
|---|
| 42 | %  specified, so some scaling might otherwise be desired. | 
|---|
| 43 | % | 
|---|
| 44 | %  dvar and dresp data would typically be contained in the dakota | 
|---|
| 45 | %  tabular output file from a sampling or parametric analysis, and | 
|---|
| 46 | %  read by dakota_out_parse. | 
|---|
| 47 | % | 
|---|
| 48 | %  "Copyright 2009, by the California Institute of Technology. | 
|---|
| 49 | %  ALL RIGHTS RESERVED. United States Government Sponsorship | 
|---|
| 50 | %  acknowledged. Any commercial use must be negotiated with | 
|---|
| 51 | %  the Office of Technology Transfer at the California Institute | 
|---|
| 52 | %  of Technology.  (J. Schiermeier, NTR 47078) | 
|---|
| 53 | % | 
|---|
| 54 | %  This software may be subject to U.S. export control laws. | 
|---|
| 55 | %  By accepting this  software, the user agrees to comply with | 
|---|
| 56 | %  all applicable U.S. export laws and regulations. User has the | 
|---|
| 57 | %  responsibility to obtain export licenses, or other export | 
|---|
| 58 | %  authority as may be required before exporting such information | 
|---|
| 59 | %  to foreign countries or providing access to foreign persons." | 
|---|
| 60 | % | 
|---|
| 61 | function []=plot_rvsv_line(varargin) | 
|---|
| 62 |  | 
|---|
| 63 | if ~nargin | 
|---|
| 64 | help plot_rvsv_line | 
|---|
| 65 | return | 
|---|
| 66 | end | 
|---|
| 67 |  | 
|---|
| 68 | %%  process input data and assemble into matrices as needed | 
|---|
| 69 |  | 
|---|
| 70 | %  variables | 
|---|
| 71 |  | 
|---|
| 72 | iarg=1; | 
|---|
| 73 | if isstruct(varargin{iarg}) | 
|---|
| 74 | dvar=varargin{iarg}; | 
|---|
| 75 | iarg=iarg+1; | 
|---|
| 76 |  | 
|---|
| 77 | %     if iarg <= nargin && (iscell(varargin{iarg}) || ischar(varargin{iarg})) | 
|---|
| 78 | if iarg <= nargin && iscell(varargin{iarg}) | 
|---|
| 79 | dvar=struc_desc(dvar,varargin{iarg}); | 
|---|
| 80 | iarg=iarg+1; | 
|---|
| 81 | end | 
|---|
| 82 |  | 
|---|
| 83 | descv=cell (1,length(dvar)); | 
|---|
| 84 | lsamp=zeros(1,length(dvar)); | 
|---|
| 85 | for i=1:length(dvar) | 
|---|
| 86 | lsamp(i)=length(dvar(i).sample); | 
|---|
| 87 | end | 
|---|
| 88 | sampv=zeros(max(lsamp),length(dvar)); | 
|---|
| 89 | sampv(:,:)=NaN; | 
|---|
| 90 |  | 
|---|
| 91 | for i=1:length(dvar) | 
|---|
| 92 | descv(i)=cellstr(dvar(i).descriptor); | 
|---|
| 93 | sampv(1:lsamp(i),i)=dvar(i).sample; | 
|---|
| 94 | end | 
|---|
| 95 | else | 
|---|
| 96 | sampv=varargin{iarg}; | 
|---|
| 97 | iarg=iarg+1; | 
|---|
| 98 |  | 
|---|
| 99 | if     iarg <= nargin && iscell(varargin{iarg}) | 
|---|
| 100 | descv=varargin{iarg}; | 
|---|
| 101 | iarg=iarg+1; | 
|---|
| 102 | %     elseif iarg <= nargin && ischar(varargin{iarg}) | 
|---|
| 103 | %         descv=cellstr(varargin{iarg}); | 
|---|
| 104 | %         iarg=iarg+1; | 
|---|
| 105 | else | 
|---|
| 106 | descv=cell(1,size(sampv,2)); | 
|---|
| 107 | end | 
|---|
| 108 | end | 
|---|
| 109 |  | 
|---|
| 110 | for i=1:length(descv) | 
|---|
| 111 | if isempty(descv{i}) | 
|---|
| 112 | descv(i)={['var_' i]}; | 
|---|
| 113 | end | 
|---|
| 114 | end | 
|---|
| 115 |  | 
|---|
| 116 | %  responses | 
|---|
| 117 |  | 
|---|
| 118 | if isstruct(varargin{iarg}) | 
|---|
| 119 | dresp=varargin{iarg}; | 
|---|
| 120 | iarg=iarg+1; | 
|---|
| 121 |  | 
|---|
| 122 | %     if iarg <= nargin && (iscell(varargin{iarg}) || ischar(varargin{iarg})) | 
|---|
| 123 | if iarg <= nargin && iscell(varargin{iarg}) | 
|---|
| 124 | dresp=struc_desc(dresp,varargin{iarg}); | 
|---|
| 125 | iarg=iarg+1; | 
|---|
| 126 | end | 
|---|
| 127 |  | 
|---|
| 128 | descr=cell (1,length(dresp)); | 
|---|
| 129 | lsamp=zeros(1,length(dresp)); | 
|---|
| 130 | for i=1:length(dresp) | 
|---|
| 131 | lsamp(i)=length(dresp(i).sample); | 
|---|
| 132 | end | 
|---|
| 133 | sampr=zeros(max(lsamp),length(dresp)); | 
|---|
| 134 | sampr(:,:)=NaN; | 
|---|
| 135 |  | 
|---|
| 136 | for i=1:length(dresp) | 
|---|
| 137 | descr(i)=cellstr(dresp(i).descriptor); | 
|---|
| 138 | sampr(1:lsamp(i),i)=dresp(i).sample; | 
|---|
| 139 | end | 
|---|
| 140 | else | 
|---|
| 141 | sampr=varargin{iarg}; | 
|---|
| 142 | iarg=iarg+1; | 
|---|
| 143 |  | 
|---|
| 144 | if     iarg <= nargin && iscell(varargin{iarg}) | 
|---|
| 145 | descr=varargin{iarg}; | 
|---|
| 146 | iarg=iarg+1; | 
|---|
| 147 | %     elseif iarg <= nargin && ischar(varargin{iarg}) | 
|---|
| 148 | %         descr=cellstr(varargin{iarg}); | 
|---|
| 149 | %         iarg=iarg+1; | 
|---|
| 150 | else | 
|---|
| 151 | descr=cell(1,size(sampr,2)); | 
|---|
| 152 | end | 
|---|
| 153 | end | 
|---|
| 154 |  | 
|---|
| 155 | for i=1:length(descr) | 
|---|
| 156 | if isempty(descr{i}) | 
|---|
| 157 | descr(i)={['resp_' num2str(i)]}; | 
|---|
| 158 | end | 
|---|
| 159 | end | 
|---|
| 160 |  | 
|---|
| 161 | %  parameters | 
|---|
| 162 |  | 
|---|
| 163 | while (iarg <= nargin-1) | 
|---|
| 164 | if ischar(varargin{iarg}) | 
|---|
| 165 | if ~isempty(strmatch(varargin{iarg},... | 
|---|
| 166 | {'nplotr','nplotc',... | 
|---|
| 167 | 'ymin','ymax','yscat'},... | 
|---|
| 168 | 'exact')) | 
|---|
| 169 | eval([varargin{iarg} '=varargin{iarg+1};']); | 
|---|
| 170 | disp([varargin{iarg} '=' any2str(varargin{iarg+1}) ';']); | 
|---|
| 171 | else | 
|---|
| 172 | warning([varargin{iarg} '=' any2str(varargin{iarg+1}) ' is not recognized.']); | 
|---|
| 173 | end | 
|---|
| 174 | else | 
|---|
| 175 | error(['''' any2str(varargin{iarg}) ''' is not a parameter name.']); | 
|---|
| 176 | end | 
|---|
| 177 | iarg=iarg+2; | 
|---|
| 178 | end | 
|---|
| 179 |  | 
|---|
| 180 | if     ~exist('nplotr','var') && ~exist('nplotc','var') | 
|---|
| 181 | nplotr=1; | 
|---|
| 182 | nplotc=1; | 
|---|
| 183 | elseif ~exist('nplotr','var') | 
|---|
| 184 | nplotr=ceil(size(sampr,2)*size(sampv,2)/nplotc); | 
|---|
| 185 | elseif ~exist('nplotc','var') | 
|---|
| 186 | nplotc=ceil(size(sampr,2)*size(sampv,2)/nplotr); | 
|---|
| 187 | end | 
|---|
| 188 |  | 
|---|
| 189 | %%  filter, sort, and plot the data | 
|---|
| 190 |  | 
|---|
| 191 | %  while it would be preferable for the outer loop to be responses, | 
|---|
| 192 | %  it is more efficient for the outer loop to be variables | 
|---|
| 193 |  | 
|---|
| 194 | figure | 
|---|
| 195 | haxes=[]; | 
|---|
| 196 | hplot=[]; | 
|---|
| 197 | cdesc={}; | 
|---|
| 198 | hscat=[]; | 
|---|
| 199 |  | 
|---|
| 200 | iplot=0; | 
|---|
| 201 |  | 
|---|
| 202 | for ivar=1:size(sampv,2) | 
|---|
| 203 | [vval,indxv,indxvi]=unique(sampv(:,ivar),'first'); | 
|---|
| 204 | indxv2=setdiff(1:size(sampv,1),indxv); | 
|---|
| 205 |  | 
|---|
| 206 | for iresp=1:size(sampr,2) | 
|---|
| 207 |  | 
|---|
| 208 | %  initialize the subplot | 
|---|
| 209 |  | 
|---|
| 210 | if (ivar*iresp == 1) || ... | 
|---|
| 211 | (nplotr*nplotc > 1) | 
|---|
| 212 | iplot=iplot+1; | 
|---|
| 213 | haxes(end+1)=subplot(nplotr,nplotc,iplot); | 
|---|
| 214 | hold all | 
|---|
| 215 | end | 
|---|
| 216 |  | 
|---|
| 217 | hplot(end+1)=plot   (sampv(indxv ,ivar),sampr(indxv ,iresp),'-x'); | 
|---|
| 218 | cdesc(end+1)={[descr{iresp} ' wrt ' descv{ivar}]}; | 
|---|
| 219 | if ~exist('yscat','var') || ... | 
|---|
| 220 | (~strncmpi(yscat,'off',3) && ~strncmpi(yscat,'n',1)) | 
|---|
| 221 | hscat(end+1)=scatter(sampv(indxv2,ivar),sampr(indxv2,iresp),'+k'); | 
|---|
| 222 | %  see "controlling legends" in Matlab on-line docs | 
|---|
| 223 | %         cdesc(end+1)={['constant ' descv{ivar}]}; | 
|---|
| 224 | set(get(get(hscat(end),'Annotation'),'LegendInformation'),... | 
|---|
| 225 | 'IconDisplayStyle','off'); % Exclude line from legend | 
|---|
| 226 | end | 
|---|
| 227 |  | 
|---|
| 228 | %  add the annotation | 
|---|
| 229 |  | 
|---|
| 230 | if (ivar*iresp == size(sampv,2)*size(sampr,2)) || ... | 
|---|
| 231 | (nplotr*nplotc > 1) | 
|---|
| 232 | hold off | 
|---|
| 233 |  | 
|---|
| 234 | ylim('auto') | 
|---|
| 235 | [ylims]=ylim; | 
|---|
| 236 | if exist('ymin','var') | 
|---|
| 237 | ylims(1)=ymin; | 
|---|
| 238 | end | 
|---|
| 239 | if exist('ymax','var') | 
|---|
| 240 | ylims(2)=ymax; | 
|---|
| 241 | end | 
|---|
| 242 | ylim(ylims) | 
|---|
| 243 |  | 
|---|
| 244 | if (size(sampv,2) == 1) || (nplotr*nplotc > 1) | 
|---|
| 245 | xlabc=descv{ivar}; | 
|---|
| 246 | else | 
|---|
| 247 | xlabc='Variables'; | 
|---|
| 248 | end | 
|---|
| 249 | if (size(sampr,2) == 1) || (nplotr*nplotc > 1) | 
|---|
| 250 | ylabc=descr{iresp}; | 
|---|
| 251 | else | 
|---|
| 252 | ylabc='Responses'; | 
|---|
| 253 | end | 
|---|
| 254 | title([ylabc ' vs. ' xlabc],'Interpreter','none'); | 
|---|
| 255 | xlabel(xlabc,'Interpreter','none'); | 
|---|
| 256 | ylabel(ylabc,'Interpreter','none'); | 
|---|
| 257 |  | 
|---|
| 258 | if (nplotr*nplotc == 1) && (size(sampv,2)*size(sampr,2) > 1) | 
|---|
| 259 | legend(cdesc,'Location','EastOutside','Interpreter','none'); | 
|---|
| 260 | end | 
|---|
| 261 | end | 
|---|
| 262 | end | 
|---|
| 263 | end | 
|---|
| 264 |  | 
|---|
| 265 | end | 
|---|