LSPLOT Plot load spectra. CALL: lsplot(LS) h = lsplot(LS,cum,norm,beta,plottype) Input: LS = Load spectra. [N,2] OR {n}[N,2] cum = 0: Plot frequencies, 1: Plot cumulative frequencies. (default) norm = 0: Use given frequencies, (default) 1: Normalize to relative frequencies. beta = Plot damage spectrum with damage exponent beta. (default beta=0) plottype = Plot load spectrum using commands: Cumulative plot: 'stairs' (default), or 'plot', Frequency plot: 'bar' (default), 'stem', 'stairs', or 'plot'. Output: h = Handles to ploted lines. [n,1] The variable LS contains either one load spectrum stored in a matrix, or a cell-array of load spectra. Each spectrum is a two collumn matrix with the amplitudes in the first column, and the frequencies in the second. See also cmat2amp, lcplot
Bar graph. | |
Clear variables and functions from memory. | |
Display message and abort function. | |
Get handle to current axis. | |
Hold current graph. | |
Return hold state. | |
True for numeric arrays. | |
Convert number to string. (Fast version) | |
Linear plot. | |
Set object properties. | |
Stairstep plot. | |
Discrete sequence or "stem" plot. | |
Compare strings. | |
X-axis label. | |
Y-axis label. |
Quick test of the routines in module 'cycles' |
001 function h=lsplot(LS,cum,norm,beta,plottype) 002 %LSPLOT Plot load spectra. 003 % 004 % CALL: lsplot(LS) 005 % h = lsplot(LS,cum,norm,beta,plottype) 006 % 007 % Input: 008 % LS = Load spectra. [N,2] OR {n}[N,2] 009 % cum = 0: Plot frequencies, 010 % 1: Plot cumulative frequencies. (default) 011 % norm = 0: Use given frequencies, (default) 012 % 1: Normalize to relative frequencies. 013 % beta = Plot damage spectrum with damage exponent beta. (default beta=0) 014 % plottype = Plot load spectrum using commands: 015 % Cumulative plot: 'stairs' (default), or 'plot', 016 % Frequency plot: 'bar' (default), 'stem', 'stairs', or 'plot'. 017 % 018 % Output: 019 % h = Handles to ploted lines. [n,1] 020 % 021 % The variable LS contains either one load spectrum stored in a matrix, or 022 % a cell-array of load spectra. Each spectrum is a two collumn matrix with 023 % the amplitudes in the first column, and the frequencies in the second. 024 % 025 % See also cmat2amp, lcplot 026 027 % Copyright (c) 2003 by Pär Johannesson 028 029 % Tested on Matlab 6.1, 6.5 030 % 031 % History: 032 % Created by TS (Thomas Svensson) 04-May-2002 033 % Updated by PJ 26-Jan-2003 034 % Updated by PJ 27-Jan-2003 035 % Changed name from RFCPLOT to LSPLOT 036 % Added plot of damage spectrum. 037 % Updated by PJ 03-Jun-2003 038 % Added input argument 'plottype' 039 % Changed name from PLOTLS to LSPLOT 040 % Updated by PJ 05-Jun-2003 041 % Now correct cumulative plot. 042 % Changed to 'stem' instead of 'plot' 043 % Updated by PJ 31-Oct-2003 044 % Now cumulative plot starts from 1 (or minimal frequency). 045 % Added 'bar' and 'stem' for frequency plot. 046 047 % Check input arguments 048 ni = nargin; 049 no = nargout; 050 error(nargchk(1,5,ni)); 051 052 if ni < 2 053 cum=[]; 054 end 055 if ni < 3 056 norm=[]; 057 end 058 if ni < 4 059 beta=[]; 060 end 061 if ni < 5 062 plottype=[]; 063 end 064 065 % Default settings 066 if isempty(cum) 067 cum=1; 068 end 069 if isempty(norm) 070 norm=0; 071 end 072 if isempty(beta) 073 beta=0; 074 end 075 if isempty(plottype) 076 if cum 077 plottype='stairs'; 078 else 079 plottype='bar'; 080 end 081 end 082 083 if isnumeric(LS), LS={LS}; end 084 n = length(LS); % Number of spectra 085 h = zeros(n,1); % Line handles 086 087 ih = ishold; 088 for k = 1:n 089 LS{k}(:,2) = LS{k}(:,1).^beta.*LS{k}(:,2); % Damage spectrum if beta>0 090 if beta > 0 091 if k==1, % Normalize damage to 1 for first spectrum 092 norm_beta =sum(LS{k}(:,2)); % 093 end 094 LS{k}(:,2) = LS{k}(:,2)/norm_beta; 095 end 096 if norm 097 LS{k}(:,2) = LS{k}(:,2)/sum(LS{k}(:,2)); 098 end 099 if cum 100 I = (LS{k}(:,2)>0); LS1 = LS{k}(I,:); 101 if strcmp(plottype,'stairs') 102 min_x = min(1,min(LS1(:,2))); 103 x = [sum(LS1(:,2))-[0; cumsum(LS1(1:end-1,2))]; min_x; 0]; 104 y = [0; LS1(:,1); LS1(end,1)]; 105 106 %LS1=[[0; LS1(:,1)] [LS1(:,2); 0] ]; 107 %LS1 = LS1(size(LS1,1):-1:1,:); 108 %h(k) = stairs(cumsum(LS1(:,2)),LS1(:,1)); 109 h(k) = stairs(flipud(x),flipud(y)); 110 elseif strcmp(plottype,'plot') 111 LS1=[[0; LS1(:,1); LS1(end,1)] [0; LS1(:,2); 0] ]; 112 LS1 = LS1(size(LS1,1):-1:1,:); 113 h(k) = plot(cumsum(LS1(:,2)),LS1(:,1)); 114 else 115 error(['Invalid plottype: ' plottype]) 116 end 117 else 118 if strcmp(plottype,'bar') 119 h(k) = bar(LS{k}(:,1),LS{k}(:,2),1); 120 elseif strcmp(plottype,'stem') 121 stem(LS{k}(:,1),LS{k}(:,2)); 122 elseif strcmp(plottype,'plot') 123 h(k) = plot(LS{k}(:,1),LS{k}(:,2)); 124 elseif strcmp(plottype,'stairs') 125 h(k) = stairs(LS{k}(:,1),LS{k}(:,2)); 126 else 127 error(['Invalid plottype: ' plottype]) 128 end 129 end 130 hold on, 131 end 132 133 if ~ih, hold off, end 134 135 if cum 136 set(gca,'xscale','log'); 137 end 138 139 140 if beta == 0 141 if cum == 0 142 ylabel('Frequency of cycles'); 143 xlabel('Amplitude'); 144 else 145 xlabel('Cumulative frequency of cycles'); 146 ylabel('Amplitude'); 147 end 148 else 149 if cum == 0 150 ylabel(['Damage per cycle, beta=' num2str(beta)]); 151 xlabel('Amplitude'); 152 else 153 xlabel(['Cumulative damage per cycle, beta=' num2str(beta)]); 154 ylabel('Amplitude'); 155 end 156 end 157 158 if no==0, clear h; end 159
Comments or corrections to the WAFO group