PDFPLOT Plot contents of pdf structures CALL: H = pdfplot(f,plotflag,x1,x2,x3,sym,method,shading) H = handle to the created object plot a PDF struct with the pollowing fields f.f = pdf f.x = cellarray of values in n dimensions (n=1:3) optional fields: f.labx = cellarray of label strings (n=1:3) f.title = title string f.cl = contour levels for 2D PDF f.pl = Percent levels the given contour lines encloses. 1D: plotflag = 1 linear (default) 2 plot 1-f(x) on a semilog y-scale 3 plot 1-f(x) on a log log scale 11 plot F(x) = cumtrapz(x,f(x)) 12 plot 1-F(x) on a semilog y-scale 13 plot 1-F(x) on a log log scale 2D: plotflag = 1 contour plot (default) 2 mesh 3 surf 4 waterfall 5 pcolor 6 contour3 3D: plotflag = 1 sliceomatic (default) 2 sliceomatic (with index x-,y-and z-labels) 3 slice 4 contour f(X1,X2,X3(x1)), where x1 is an integer 5 contour f(X1(x1),X2,X3), where x1 is an integer 6 contour f(X1,X2(x1),X3), where x1 is an integer x1,x2,x3 = are vectors defining where to slice for 3D data (default along the axis where f has its maximum) sym = plot symbol (default '-') method = interpolation method for 3D slice 'linear' (default), 'cubic', or 'nearest' shading = controls the color shading of SURFACE and PATCH objects. 'faceted' (default), flat or 'interp' Note: - sym,method and shading can be given anywhere after f and in any order. See also datastructures, qlevels, cltext
Places contour level text in the current window | |
Display colorbar with discrete color axis for filled contour plot | |
Plot contents of pdf structures | |
Calculates the difference between the maximum and minimum values. | |
Prints a caption "made by WAFO" in current figure. | |
Control axis scaling and appearance. | |
Functions on cell array contents. | |
Contour plot elevation labels. | |
Contour plot. | |
3-D contour plot. | |
Filled contour plot. | |
Contouring over non-rectangular surface. | |
Cumulative trapezoidal numerical integration. | |
Display message and abort function. | |
Check if variables or functions are defined. | |
Create figure window. | |
find all objects. | |
Get handle to current axis. | |
Get handle to current figure. | |
Get object properties. | |
Hold current graph. | |
Multiple subscripts from linear index. | |
True for character array (string). | |
True if field is in structure array. | |
Return hold state. | |
True for structures. | |
Log-log scale plot. | |
Convert string to lowercase. | |
3-D mesh surface. | |
X and Y arrays for 3-D plots. | |
Not-a-Number. | |
M-file preamble for NextPlot property. | |
Convert number to string. (Fast version) | |
Pseudocolor (checkerboard) plot. | |
Linear plot. | |
Semi-log scale plot. | |
Set object properties. | |
Color shading mode. | |
Volumetric slice plot. | |
- Slice and isosurface volume exploration GUI | |
Remove singleton dimensions. | |
3-D colored surface. | |
Set unique. | |
Display warning message; disable or enable warning messages. | |
Waterfall plot. | |
X-axis label. | |
Y-axis label. | |
Z-axis label. |
Cavanie et al. (1976) approximation of the density (Tc,Ac) | |
% CHAPTER1 demonstrates some applications of WAFO | |
% CHAPTER3 Demonstrates distributions of wave characteristics | |
% CHAPTER4 contains the commands used in Chapter 4 of the tutorial | |
Smooths the conditional DIST2D distribution parameters. | |
Script to computer exercises 3 | |
GUI to Kernel Density Estimator. | |
GUI to Kernel Density Estimator in two dimensions. | |
Demonstrate the smoothing parameter impact on KDE | |
Demonstrate the difference between transformation- and ordinary-KDE | |
Longuet-Higgins (1983) approximation of the density (Tc,Ac) | |
Plot contents of pdf structures | |
Joint distribution of V and H: | |
Evaluates survival function R(h1,h2)=P(Ac>h1,At>h2). | |
Evaluates cdf of crests P(Ac<=h) or troughs P(At<=h). | |
Evaluates densities of wave period Tcc, wave lenght Lcc. | |
Joint density of amplitude and period/wave-length characteristics | |
Evaluates densities for crest-,trough-period, length. | |
Evaluates densities for various wave periods or wave lengths | |
Intensity of trough-crest cycles computed from St | |
Probability density distributions (pdf) of wave period, Tt, | |
Joint distribution (pdf) of crest front velocity and wave height: | |
Joint distribution (pdf) of crest front period, Tcf, and crest amplitude, Ac | |
Joint distribution (pdf) of crest wavelength, Lc, and crest amplitude, Ac | |
Joint distribution (pdf) of crest wavelength, Lc, and crest amplitude, Ac for extremal waves | |
Intensity of rainflow cycles computed from St |
0001 function H1=pdfplotpdfplot(f,varargin) 0002 %PDFPLOT Plot contents of pdf structures 0003 % 0004 % CALL: H = pdfplot(f,plotflag,x1,x2,x3,sym,method,shading) 0005 % 0006 % H = handle to the created object 0007 % 0008 % plot a PDF struct with the pollowing fields 0009 % 0010 % f.f = pdf 0011 % f.x = cellarray of values in n dimensions (n=1:3) 0012 % 0013 % optional fields: 0014 % f.labx = cellarray of label strings (n=1:3) 0015 % f.title = title string 0016 % f.cl = contour levels for 2D PDF 0017 % f.pl = Percent levels the given contour 0018 % lines encloses. 0019 % 1D: 0020 % plotflag = 1 linear (default) 0021 % 2 plot 1-f(x) on a semilog y-scale 0022 % 3 plot 1-f(x) on a log log scale 0023 % 11 plot F(x) = cumtrapz(x,f(x)) 0024 % 12 plot 1-F(x) on a semilog y-scale 0025 % 13 plot 1-F(x) on a log log scale 0026 % 2D: 0027 % plotflag = 1 contour plot (default) 0028 % 2 mesh 0029 % 3 surf 0030 % 4 waterfall 0031 % 5 pcolor 0032 % 6 contour3 0033 % 3D: 0034 % plotflag = 1 sliceomatic (default) 0035 % 2 sliceomatic (with index x-,y-and z-labels) 0036 % 3 slice 0037 % 4 contour f(X1,X2,X3(x1)), where x1 is an integer 0038 % 5 contour f(X1(x1),X2,X3), where x1 is an integer 0039 % 6 contour f(X1,X2(x1),X3), where x1 is an integer 0040 % x1,x2,x3 = are vectors defining where to slice for 3D data 0041 % (default along the axis where f has its maximum) 0042 % sym = plot symbol (default '-') 0043 % method = interpolation method for 3D slice 0044 % 'linear' (default), 'cubic', or 'nearest' 0045 % shading = controls the color shading of SURFACE and PATCH 0046 % objects. 'faceted' (default), flat or 'interp' 0047 % 0048 % Note: - sym,method and shading can be given anywhere after f and in 0049 % any order. 0050 % 0051 % See also datastructures, qlevels, cltext 0052 0053 % Note: is only able to handle 1D,2D and 3D plot i.e. ndim=3 0054 0055 %Tested on: Matlab 5.3, 5.2 0056 %History: 0057 % revised pab March 2005 0058 % -fixed some bugs 0059 % revised pab 27.11.2002 0060 % -added sliceomatic call -> reordered the plotflag order 0061 % revised pab 07.01.2001 0062 % - fixed a bug for slice option 3D, reordered plotflag options for 1D. 0063 % revised pab 23.11.2000 0064 % - fixed a bug for calculation of contourlevels when f is not a pdf 0065 % revised pab 08.11.2000 0066 % - added the possibility that f is an array of structs 0067 % - added plotflag 2,3 and 4 for 1D 0068 % revised pab 15.05.2000 0069 % - added shading, contour3 0070 % - now slicing along the axis where f has its maximum 0071 % % revised pab 28.01.2000 0072 % - added point-and-click editing of all the text objects (title, 0073 % xlabel, ylabel) of the current figure 0074 % - improved the printing of contour level text and moved it into a 0075 % separate function cltext (this may be further improved) 0076 % - changed see also line 0077 % revised es 24.01.2000 - dim=length(f.x) improving old, added som missing ; 0078 % revised pab 20.01.2000 0079 % - added pcolor 0080 % revised pab 18.01.2000 0081 % - added return statement if plotflag==0 0082 % - added slice for 3D visualization 0083 % - added hold_state 0084 % - added pdfplotchk 0085 % revised pab 5.11.1999 0086 % - changed PL to pl and CL to cl 0087 % by pab 12.08.99 0088 0089 if ~isstruct(f) % secret option plot a matrix assuming the first column 0090 % is the independent variable 0091 [plotflag,sym] = pdfplotchk(varargin,1); 0092 switch plotflag 0093 case 0, return 0094 case 1, H = plot(f(:,1),f(:,2:end),sym); 0095 case 2, H = semilogy(f(:,1),1-f(:,2:end),sym); 0096 case 3, H = loglog(f(:,1),-log(1-f(:,2:end)),sym); 0097 case 4, H = semilogy(f(:,1),f(:,2:end),sym); 0098 case 5, H = loglog(f(:,1),-log(f(:,2:end)),sym); 0099 case 6, m = size(f,2) 0100 H = waterfall(f(:,1),1:m,f(:,2:end)); 0101 case 11, H = plot(f(:,1),cumtrapz(f(:,1),f(:,2:end)),sym); 0102 case 12, H = semilogy(f(:,1),1-cumtrapz(f(:,1),f(:,2:end)),sym); 0103 case 13, H = loglog(f(:,1),-log(1-cumtrapz(f(:,1),f(:,2:end))),sym); 0104 otherwise, error('Unknown option for plotflag') 0105 end 0106 axis('square') 0107 set(gca,'FontSize',12) 0108 wafostamp; 0109 if (nargout>=1), H1=H; end 0110 return 0111 end 0112 hold_state = ishold; % remember old hold state 0113 Nff=length(f); 0114 if Nff>1 0115 cfig=gcf; 0116 for ix=1:Nff, 0117 if hold_state 0118 newplot 0119 else 0120 figure(cfig-1+ix) 0121 end 0122 pdfplot(f(ix),varargin{:}) 0123 end 0124 return 0125 end 0126 0127 cax = newplot; % axes 0128 cfig = get(cax,'Parent'); %cfig=gcf; 0129 0130 dim = length(f.x); 0131 if dim>length(size(squeeze(f.f))) 0132 fsiz=size(f.f) 0133 dim=length(fsiz)-sum(fsiz==1); % Number of non-singleton dimensions 0134 end 0135 %dim, 0136 [plotflag,sym,method,shad,x1,x2,x3] = pdfplotchk(varargin,dim,f); 0137 if plotflag==0, return,end 0138 switch dim 0139 case 1, %1D 0140 switch plotflag 0141 case 1, H=plot(f.x{1},f.f,sym); 0142 case 2, H=semilogy(f.x{1},1-f.f,sym); 0143 case 3, H=loglog(f.x{1},-log(1-f.f),sym); 0144 case 11, H=plot(f.x{1},cumtrapz(f.x{1},f.f),sym); 0145 case 12, H=semilogy(f.x{1},1-cumtrapz(f.x{1},f.f),sym); 0146 case 13, H=loglog(f.x{1},-log(1-cumtrapz(f.x{1},f.f)),sym); 0147 end 0148 case 2 %2D 0149 switch plotflag 0150 case {1,6,7,8,9}, 0151 PL=0; 0152 if isfield(f,'cl')&~isempty(f.cl) % check if contour levels is submitted 0153 CL=f.cl; 0154 if isfield(f,'pl'),PL=~isempty(f.pl);end % levels defines quantile levels? 0=no 1=yes 0155 else 0156 CL=max(f.f(:))-range(f.f(:))*(1-[0.01 0.025 0.05 0.1 0.2 0.4 0.5 0.75]); 0157 if 0 % automatic levels by using contours 0158 c=contours(f.x{:},f.f.'); % calculate 8 levels 0159 if isempty(c) 0160 c=contours(f.x{:},f.f);%,7); % calculate levels 0161 end 0162 %CL = clevels(c); 0163 limit = size(c,2); 0164 ix = 1; 0165 while(ix < limit) 0166 CL(ix) = c(1,ix); 0167 npoints = c(2,ix); 0168 nexti = ix+npoints+1; 0169 c(:,ix)=NaN; 0170 ix = nexti; 0171 end 0172 CL=unique(CL); 0173 end 0174 end 0175 if PL, 0176 clvec=sort(f.pl); 0177 else 0178 clvec=sort(CL); 0179 end 0180 if any(plotflag==[1 8 9]) 0181 [cs hcs] = contour(f.x{:},f.f,CL,sym); 0182 else 0183 [cs hcs] = contour3(f.x{:},f.f,CL,sym); 0184 end 0185 if any(plotflag==[1,6]) 0186 ncl=length(clvec); 0187 if ncl>12, ncl=12; disp(' Only the first 12 levels will be listed in table.'),end 0188 [hcl, axcl]=cltext(clvec(1:ncl),PL); % print contour level text 0189 elseif any(plotflag==[7 9]) 0190 clabel(cs); 0191 else 0192 clabel(cs,hcs); 0193 end 0194 0195 case 2, mesh(f.x{:},f.f); % meshz 0196 case 3, surf(f.x{:},f.f); %shading interp % flat, faceted % surfc 0197 case 4, waterfall(f.x{:},f.f); 0198 case 5, pcolor(f.x{:},f.f); %shading interp % flat, faceted 0199 case 10, 0200 [cs,hcs]=contourf(f.x{:},f.f); clabel(cs,hcs); fcolorbar(cs); 0201 otherwise, error('unknown option for plotflag') 0202 end 0203 if any(plotflag==[2:5]) 0204 shading(shad); 0205 end 0206 case 3, %3D 0207 switch plotflag 0208 case 1, 0209 sliceomatic(f.x{:},f.f) 0210 case 2, 0211 sliceomatic(f.f) 0212 case 3, 0213 [X,Y,Z]=meshgrid(f.x{:}); 0214 %method='linear';%, 'cubic','spline', or 'nearest' 0215 slice(X,Y,Z,f.f,x1,x2,x3,method); 0216 shading(shad); 0217 case 4, 0218 x1 = round(x1); 0219 contour(f.x{1:2},f.f(:,:,x1)); 0220 if isempty(f.labx{3}),f.labx{3}='x3';end 0221 f.title=[f.title f.labx{3} ' = ' num2str(f.x{3}(x1))]; 0222 f.labx{3}=[]; 0223 case 5, 0224 x1 = round(x1); 0225 contour(f.x{[2 3]},squeeze(f.f(:,x1,:)).'); 0226 if isempty(f.labx{1}),f.labx{1}='x1';end 0227 f.title=[f.title f.labx{1} ' = ' num2str(f.x{1}(x1))]; 0228 f.labx{1}=[]; 0229 f.labx=f.labx([2 3 1]); 0230 case 6, 0231 x1 = round(x1); 0232 contour(f.x{[1 3]},squeeze(f.f(x1,:,:)).'); 0233 if isempty(f.labx{1}),f.labx{2}='x2';end 0234 f.title=[f.title f.labx{2} ' = ' num2str(f.x{2}(x1))]; 0235 f.labx{2}=[]; 0236 f.labx=f.labx([1 3 2]); 0237 end 0238 end 0239 if isfield(f,'labx') & max(size(f.labx))>=1 0240 Nf=max(size(f.labx)); 0241 if Nf>=3, zlabel(f.labx{3}), end 0242 if Nf>=2, ylabel(f.labx{2}), end 0243 xlabel(f.labx{1}) 0244 end 0245 if isfield(f,'title') 0246 title(f.title) 0247 end 0248 0249 if exist('axcl','var'),% & ~isempty(axcl) 0250 set(cfig,'currentaxes',axcl(1)) 0251 axis('square') 0252 set(cfig,'currentaxes',cax(1)) 0253 end 0254 axis('square') 0255 set(gca,'FontSize',12) 0256 wafostamp; 0257 0258 % The following two commands install point-and-click editing of 0259 % all the text objects (title, xlabel, ylabel) of the current figure: 0260 0261 set(findall(gcf,'type','text'),'buttondownfcn','edtext') 0262 set(gcf,'windowbuttondownfcn','edtext(''hide'')') 0263 0264 0265 if ~hold_state, 0266 hold off, 0267 %set(cfig,'NextPlot', 'replace'); 0268 end % reset to old hold state 0269 0270 if (nargout>=1) 0271 H1=H; 0272 end 0273 return 0274 0275 0276 0277 function [plotflag,sym,method,shad,x1,x2,x3] = pdfplotchk(P,dim,f) 0278 %pdfplotCHK Helper function for pdfplot. 0279 % 0280 % CALL [plotflag,sym,method,shad,x1,x2,x3]=pdfplotchk(P,dim) 0281 % 0282 % P = the cell array P of input arguments (between 0 and 6 elements) 0283 0284 0285 % initialize output to default values 0286 plotflag = 1; 0287 sym='k-'; % Black dots is default 0288 method='linear'; % linear is default 0289 shad ='faceted'; 0290 if dim==3 0291 % Old call 0292 %x1=mean(f.x{1});x2=mean(f.x{2});x3=mean(f.x{3}); 0293 % New call slicing where the maximum value is located 0294 [fmax, ind] = max(f.f(:)); 0295 [I2,I1,I3] = ind2sub(size(f.f),ind); 0296 x1=f.x{1}(I1);x2=f.x{2}(I2);x3=f.x{3}(I3); 0297 else 0298 x1=[];x2=[];x3=[]; 0299 end 0300 0301 Np=length(P); 0302 try 0303 strix = cellfun('isclass',P,'char'); 0304 catch 0305 strix=zeros(1,Np); 0306 for ix=1:Np, % finding symbol strings 0307 strix(ix)=ischar(P{ix}); 0308 end 0309 end 0310 k=find(strix); 0311 if any(k) % remove strings 0312 Nk=length(k); 0313 if Nk>3 0314 warning('More than 3 strings are not allowed in ') 0315 end 0316 for ix=1:length(k) 0317 switch lower(P{k(ix)}) 0318 case {'flat','faceted','interp'} , shad = P{k(ix)}; 0319 case {'linear','cubic', 'nearest'}, method = P{k(ix)}; 0320 otherwise % plotsymbol is given 0321 sym = P{k(ix)}; 0322 end 0323 end 0324 Np=Np-length(k); 0325 P={P{find(~strix)}}; % remove strings from input 0326 end 0327 0328 0329 if (Np>0) & ~isempty(P{1}) 0330 plotflag=P{1}; 0331 end 0332 if dim==3 0333 switch plotflag 0334 case {1,2,3}, % do nothing 0335 case 4, x1 = I3; 0336 case 5, x1 = I1; 0337 case 6, x1 = I2; 0338 end 0339 end 0340 0341 0342 if (Np>1) & ~isempty(P{2}) 0343 x1=P{2}; 0344 end 0345 if (Np>2) & ~isempty(P{3}) 0346 x2=P{3}; 0347 end 0348 0349 if (Np>3) & ~isempty(P{4}) 0350 x3=P{4}; 0351 end 0352 return
Comments or corrections to the WAFO group