source: issm/trunk-jpl/src/m/qmu/plot/plot_rvsv_scat3.m

Last change on this file was 13646, checked in by Mathieu Morlighem, 12 years ago

CHG: cosmetics, removed multiple blank lines

File size: 7.8 KB
Line 
1%
2% plot 3-d scatter plots of variables vs. responses.
3%
4% []=plot_rvsv_scat3(dvar ,dresp ,params)
5% []=plot_rvsv_scat3(dvar ,descv,dresp,descr,params)
6% []=plot_rvsv_scat3(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% zmin (numeric, minimum of z-axis)
38% zmax (numeric, maximum of z-axis)
39% cmin (numeric, minimum of colorbar)
40% cmax (numeric, maximum of colorbar)
41% smark (numeric, size of markers)
42%
43% for each response in the input array, this function plots a 3-d
44% scatter plot. there should be no more than three variables.
45% each response will be in a separate scatter plot; hence the
46% need for nplotr and nplotc.
47%
48% dvar and dresp data would typically be contained in the dakota
49% tabular output file from a sampling or parametric analysis, and
50% read by dakota_out_parse.
51%
52% "Copyright 2009, by the California Institute of Technology.
53% ALL RIGHTS RESERVED. United States Government Sponsorship
54% acknowledged. Any commercial use must be negotiated with
55% the Office of Technology Transfer at the California Institute
56% of Technology. (J. Schiermeier, NTR 47078)
57%
58% This software may be subject to U.S. export control laws.
59% By accepting this software, the user agrees to comply with
60% all applicable U.S. export laws and regulations. User has the
61% responsibility to obtain export licenses, or other export
62% authority as may be required before exporting such information
63% to foreign countries or providing access to foreign persons."
64%
65function []=plot_rvsv_scat3(varargin)
66
67if ~nargin
68 help plot_rvsv_scat3
69 return
70end
71
72%% process input data and assemble into matrices as needed
73
74iarg=1;
75
76% variables
77
78if isstruct(varargin{iarg})
79 dvar=varargin{iarg};
80 iarg=iarg+1;
81
82% if iarg <= nargin && (iscell(varargin{iarg}) || ischar(varargin{iarg}))
83 if iarg <= nargin && iscell(varargin{iarg})
84 dvar=struc_desc(dvar,varargin{iarg});
85 iarg=iarg+1;
86 end
87
88 descv=cell (1,length(dvar));
89 lsamp=zeros(1,length(dvar));
90 for i=1:length(dvar)
91 lsamp(i)=length(dvar(i).sample);
92 end
93 sampv=zeros(max(lsamp),length(dvar));
94 sampv(:,:)=NaN;
95
96 for i=1:length(dvar)
97 descv(i)=cellstr(dvar(i).descriptor);
98 sampv(1:lsamp(i),i)=dvar(i).sample;
99 end
100else
101 sampv=varargin{iarg};
102 iarg=iarg+1;
103
104 if iarg <= nargin && iscell(varargin{iarg})
105 descv=varargin{iarg};
106 iarg=iarg+1;
107% elseif iarg <= nargin && ischar(varargin{iarg})
108% descv=cellstr(varargin{iarg});
109% iarg=iarg+1;
110 else
111 descv=cell(1,size(sampv,2));
112 end
113end
114
115for i=1:length(descv)
116 if isempty(descv{i})
117 descv(i)={['var_' i]};
118 end
119end
120
121if (size(sampv,2) > 3)
122 error('No more than three variables required for 3-d scatter plot.');
123end
124
125% responses
126
127if isstruct(varargin{iarg})
128 dresp=varargin{iarg};
129 iarg=iarg+1;
130
131% if iarg <= nargin && (iscell(varargin{iarg}) || ischar(varargin{iarg}))
132 if iarg <= nargin && iscell(varargin{iarg})
133 dresp=struc_desc(dresp,varargin{iarg});
134 iarg=iarg+1;
135 end
136
137 descr=cell (1,length(dresp));
138 lsamp=zeros(1,length(dresp));
139 for i=1:length(dresp)
140 lsamp(i)=length(dresp(i).sample);
141 end
142 sampr=zeros(max(lsamp),length(dresp));
143 sampr(:,:)=NaN;
144
145 for i=1:length(dresp)
146 descr(i)=cellstr(dresp(i).descriptor);
147 sampr(1:lsamp(i),i)=dresp(i).sample;
148 end
149else
150 sampr=varargin{iarg};
151 iarg=iarg+1;
152
153 if iarg <= nargin && iscell(varargin{iarg})
154 descr=varargin{iarg};
155 iarg=iarg+1;
156% elseif iarg <= nargin && ischar(varargin{iarg})
157% descr=cellstr(varargin{iarg});
158% iarg=iarg+1;
159 else
160 descr=cell(1,size(sampr,2));
161 end
162end
163
164for i=1:length(descr)
165 if isempty(descr{i})
166 descr(i)={['resp_' num2str(i)]};
167 end
168end
169
170% parameters
171
172while (iarg <= nargin-1)
173 if ischar(varargin{iarg})
174 if ~isempty(strmatch(varargin{iarg},...
175 {'nplotr','nplotc',...
176 'ymin','ymax','zmin','zmax',...
177 'cmin','cmax','smark'},...
178 'exact'))
179 eval([varargin{iarg} '=varargin{iarg+1};']);
180 disp([varargin{iarg} '=' any2str(varargin{iarg+1}) ';']);
181 else
182 warning([varargin{iarg} '=' any2str(varargin{iarg+1}) ' is not recognized.']);
183 end
184 else
185 error(['''' any2str(varargin{iarg}) ''' is not a parameter name.']);
186 end
187 iarg=iarg+2;
188end
189
190if ~exist('nplotr','var') && ~exist('nplotc','var')
191 nplotr=ceil(sqrt(size(sampr,2)));
192 nplotc=ceil(size(sampr,2)/nplotr);
193elseif ~exist('nplotr','var')
194 nplotr=ceil(size(sampr,2)/nplotc);
195elseif ~exist('nplotc','var')
196 nplotc=ceil(size(sampr,2)/nplotr);
197end
198
199if ~exist('smark','var')
200 smark=100;
201end
202
203%% filter, sort, and plot the data
204
205figure
206haxes =[];
207hscat3=[];
208
209for iresp=1:size(sampr,2)
210
211% initialize the subplot
212
213 haxes(end+1)=subplot(nplotr,nplotc,iresp);
214 switch size(sampv,2)
215 case 1
216 hscat3(end+1)=scatter (sampv(:,1),sampr(:,iresp),...
217 smark,sampr(:,iresp),'filled');
218 case 2
219 hscat3(end+1)=scatter3(sampv(:,1),sampv(:,2),sampr(:,iresp),...
220 smark,sampr(:,iresp),'filled');
221 case 3
222 hscat3(end+1)=scatter3(sampv(:,1),sampv(:,2),sampv(:,3),...
223 smark,sampr(:,iresp),'filled');
224 end
225
226 ylim('auto')
227 [ylims]=ylim;
228 if exist('ymin','var')
229 ylims(1)=ymin;
230 end
231 if exist('ymax','var')
232 ylims(2)=ymax;
233 end
234 ylim(ylims)
235
236 zlim('auto')
237 [zlims]=zlim;
238 if exist('zmin','var')
239 zlims(1)=zmin;
240 end
241 if exist('zmax','var')
242 zlims(2)=zmax;
243 end
244 zlim(zlims)
245
246% add the annotation
247
248 switch size(sampv,2)
249 case 1
250 title([descr{iresp} ' wrt ' descv{1}],...
251 'Interpreter','none');
252 xlabel(descv{1},'Interpreter','none');
253 ylabel(descr{iresp},'Interpreter','none');
254 case 2
255 title([descr{iresp} ' wrt ' descv{1} ' and ' descv{2}],...
256 'Interpreter','none');
257 xlabel(descv{1},'Interpreter','none');
258 ylabel(descv{2},'Interpreter','none');
259 zlabel(descr{iresp},'Interpreter','none');
260 case 3
261 title([descr{iresp} ' wrt ' descv{1} ' and ' descv{2} ' and ' descv{3}],...
262 'Interpreter','none');
263 xlabel(descv{1},'Interpreter','none');
264 ylabel(descv{2},'Interpreter','none');
265 zlabel(descv{3},'Interpreter','none');
266 end
267
268 caxis('auto')
269 [cmini,cmaxi]=caxis;
270 if exist('cmin','var')
271 cmini=cmin;
272 end
273 if exist('cmax','var')
274 cmaxi=cmax;
275 end
276 caxis([cmini cmaxi])
277
278 colorbar
279end
280
281end
Note: See TracBrowser for help on using the repository browser.