WAVEPLOT Plots the surface elevation of timeseries. CALL: waveplot(x1,x2,Nsub,Nf,Sm0,v_fact,sym1,sym2) x1, x2 = two-column timeseries first column sampling times [sec] second column surface elevation [m] x2 is by default zero-separated troughs and crests. Nsub = Number of subplots in each figure. By default Nsub is such that there are about 20 mean down crossing waves in each subplot. If Nf is not given and Nsub is larger than 6 then Nsub is changed to Nsub=min(6,ceil(Nsub/Nf)) Nf = Number of figures. By default Nf=ceil(Nsub/6). Sm0 = standard deviation of x1. v_fact = how large in stdev the vertical scale should be (default 3) sym1, sym2 = plot symbol and color for x1 and x2, respectively (see PLOT) (default 'k.' and 'k+') Note: - sym1 and sym2 can be given anywhere after x1. if omitted default values are used. - x2 can be omitted, but if given it must appear before the scalars Nsub,Nf,Sm0 and v_fact. - if [] is given for any of the scalars default values are used. Example: Plot x1 with red lines and mark troughs and crests with blue circles. x = load('sea.dat'); x1 = x(1:50,:); waveplot(x1,'r-','bo') See also dat2tc, plot
Extracts troughs and crests from data. | |
Places text in figure window. | |
Control axis scaling and appearance. | |
Display message and abort function. | |
Create figure window. | |
Get handle to current axis. | |
Get handle to current figure. | |
Hold current graph. | |
True for character array (string). | |
Return hold state. | |
Convert number to string. (Fast version) | |
Linear plot. | |
Set object properties. | |
Standard deviation. | |
Create axes in tiled positions. | |
Graph title. | |
X-axis label. | |
Y-axis label. |
% CHAPTER1 demonstrates some applications of WAFO | |
% CHAPTER2 Modelling random loads and stochastic waves | |
Finds the indices to spurious points in a timeseries | |
Example of the reconstructed (solid) and original data set (pluses) | |
reconstruct the spurious/missing points of timeseries | |
Linear simulation from a Torsethaugen spectrum. |
001 function Nf1 = waveplot(x,varargin) 002 %WAVEPLOT Plots the surface elevation of timeseries. 003 % 004 % CALL: waveplot(x1,x2,Nsub,Nf,Sm0,v_fact,sym1,sym2) 005 % 006 % x1, x2 = two-column timeseries 007 % first column sampling times [sec] 008 % second column surface elevation [m] 009 % x2 is by default zero-separated troughs and crests. 010 % Nsub = Number of subplots in each figure. By default 011 % Nsub is such that there are about 20 mean down 012 % crossing waves in each subplot. If Nf is not 013 % given and Nsub is larger than 6 then Nsub is 014 % changed to Nsub=min(6,ceil(Nsub/Nf)) 015 % Nf = Number of figures. By default Nf=ceil(Nsub/6). 016 % Sm0 = standard deviation of x1. 017 % v_fact = how large in stdev the vertical scale should be (default 3) 018 % sym1, sym2 = plot symbol and color for x1 and x2, respectively 019 % (see PLOT) (default 'k.' and 'k+') 020 % 021 % Note: - sym1 and sym2 can be given anywhere after x1. 022 % if omitted default values are used. 023 % - x2 can be omitted, but if given it must appear 024 % before the scalars Nsub,Nf,Sm0 and v_fact. 025 % - if [] is given for any of the scalars default values are used. 026 % 027 % Example: Plot x1 with red lines and mark troughs and crests with 028 % blue circles. 029 % x = load('sea.dat'); 030 % x1 = x(1:50,:); 031 % waveplot(x1,'r-','bo') 032 % 033 % See also dat2tc, plot 034 035 %Tested on: Matlab 6.0, 5.3, 5.2, 5.1 036 % History: 037 % revised jr 02.04.2001 038 % - added example, updated info. 039 % revised pab 11.10.2000 040 % - bug fix: disabled subplot when Nsub=1 => may use waveplot to 041 % overplot other figures 042 % revised pab 01.02.2000 043 % - fixed a bug in hour scale 044 % - temporarily disabled this function 045 % revised pab 03.12.1999 046 % - changed input to varargin, removed Nw 047 % - added hour and minute scale for horizontal axis i.e. dT 048 % last modified Per A. Brodtkorb 01.10.98 049 % to accept missing values NaN's 050 % revised pab 15.08.98 051 % 052 xn=x; 053 054 [n m]= size(xn); 055 if n<m 056 b=m;m=n;n=b; 057 xn=xn'; 058 end 059 060 if n<2, 061 error('The vector must have more than 2 elements!') 062 end 063 064 istime=1; 065 066 switch m 067 case 1, xn=[ (1:n)' xn(:)];istime=0; 068 case 2, % dimension OK! 069 otherwise, error('Wrong dimension of input! dim must be 2xN, 1xN, Nx2 or Nx1 ') 070 end 071 072 [TP1,Nsub,Nf,Sm0,sym1,sym2, v_fact] = wavechk(varargin,xn); 073 074 Ns = floor(n/(Nf*Nsub)); 075 ind = [1:Ns]; 076 if all(xn(:,2)>=0) 077 v_scale = [0 2*Sm0]*v_fact; 078 else 079 v_scale = [-Sm0 Sm0]*v_fact; 080 end 081 if istime 082 XlblTxt='Time (sec) ';dT=1; 083 if 1, % disable other scalings pab 01.02.2000 084 if abs(xn(ind(1),1)-xn(ind(Ns),1))>18000, % more than 5 hours 085 dT=1/(60*60); 086 XlblTxt='Time (hours) '; 087 elseif abs(xn(ind(1),1)-xn(ind(Ns),1))>300,% more than 5 minutes 088 dT=1/60; 089 XlblTxt='Time (minutes) '; 090 end 091 end 092 else 093 dT=1; 094 XlblTxt='Step '; 095 end 096 097 indmiss=isnan(xn(:,2)); % indices to missing points 098 if max(abs(xn(~indmiss,2)))>5*Sm0, 099 XlblTxt=[ XlblTxt '(Spurious data since max > 5 std.)']; 100 end 101 start=gcf-1; % start at current figure 102 hstate = ishold; 103 104 for iz=1:Nf 105 if Nf>1,figure(start+iz);end 106 for ix=1:Nsub, 107 if Nsub>1,subplot(Nsub,1,ix),end 108 if hstate, hold on; end 109 h_scale=[xn(ind(1),1) xn(ind(Ns),1)]*dT; 110 plot(xn(ind,1)*dT,xn(ind,2:end),sym1) , hold on 111 plot(TP1(:,1)*dT,TP1(:,2:end),sym2) 112 plot(h_scale,[0 0],'k') 113 axis([h_scale v_scale]) 114 115 for iy=[-2 2], 116 plot(h_scale,iy*Sm0*[1 1],'--') 117 switch sign(iy) 118 case -1, sign1='-'; 119 case 0, sign1=' '; 120 case 1, sign1='+'; 121 end 122 figtext(0.99,iy*Sm0,['- ' sign1 num2str(abs(iy)) ],'norm','data') 123 124 end, hold off 125 126 ind = ind + Ns; 127 end 128 129 xlabel(XlblTxt) 130 131 if Nsub>1,subplot(Nsub,1,1),end 132 133 title('Surface elevation from mean water level (MWL).') 134 135 if Nsub>1,subplot(Nsub,1,floor((Nsub+1)/2)),end 136 if (Sm0 >1.1)|(Sm0<0.9), % surface elevation is probably not standardized 137 ylabel('Distance from MWL.(m)') 138 end 139 set(gca,'DefaultTextRotation',90) 140 figtext(1.05,0,'Standard Deviation','norm','data','center') 141 set(gca,'DefaultTextRotation',0) 142 143 end 144 145 if nargout>0, 146 Nf1=Nf 147 end 148 149 %subplot(111) 150 return 151 152 153 function [x2,Nsub,Nf,Sm0,sym1,sym2, vfact] = wavechk(P,x1) 154 %WAVECHK Helper function for waveplot. 155 % 156 % CALL [x2, Nsub,Nf,Sm0,sym1,sym2, vfact]=wavechk(P,x1) 157 % 158 % P = the cell array P of input arguments (between 0 and 7 elements) 159 % x1 = must be a two column vector. 160 161 162 Nw=20; 163 Np=length(P); 164 strix=zeros(1,Np); 165 for ix=1:Np, % finding symbol strings 166 strix(ix)=ischar(P{ix}); 167 end 168 sym1='k.'; % Black dots is default 169 sym2='k+'; % Black plus is default 170 k=find(strix); 171 if any(k) 172 sym1=P{k(1)}; 173 Np=Np-1; 174 if length(k)>1 175 sym2=P{k(2)}; 176 Np=Np-1; 177 end 178 end 179 180 P={P{find(~strix)}}; 181 182 indmiss=isnan(x1(:,2)); % indices to missing points 183 if (Np>0) & (prod(size(P{1}))>1) 184 x2=P{1}; 185 P={P{2:Np}}; 186 Np=Np-1; 187 else 188 x2=dat2tc(x1(~indmiss,:),0,'tw'); % Finding mean separated turning points 189 %TP1=data2tp(xn,0.2,'mw'); % Finding rf waves 190 %TP1=dat2tp(xn,0.2); 191 end 192 193 if (Np >= 1) & ~isempty(P{1}) 194 % waveplot(x1,x2,Nsub) 195 Nsub=P{1}; 196 else 197 Nsub=floor(length(x2)/(2*Nw))+1; % about Nw mdc waves in each plot 198 end 199 200 if (Np >= 2) & ~isempty(P{2}) 201 % waveplot(x1,x2,Nsub,Nf) 202 Nf=P{2}; 203 else 204 Nf=ceil(Nsub/6); 205 Nsub=min(6,ceil(Nsub/Nf)); 206 end 207 if (Np >= 3) & ~isempty(P{3}) 208 % waveplot(x1,x2,Nsub,Nf,Sm0) 209 Sm0=P{3}; 210 else 211 Sm0=std(x1(~indmiss,2)); 212 end 213 if (Np >= 4) & ~isempty(P{4}) 214 % waveplot(x1,x2,Nsub,Nf,Sm0,v_fact) 215 vfact=P{4}; 216 else 217 vfact=3; % 3 std default 218 end 219
Comments or corrections to the WAFO group