%% Cycle Counts of Identified Reversals
% Generate a set of extrema resembling load reversals. Plot the data.

X = [-2 1 -3 5 -1 3 -4 4 -2]';

plot(X)
xlabel('Sample Index')  
ylabel('Stress')

%
% Compute cycle counts for the data. Specify that the input consists of already identified extrema.

[C,hist,edges] = rainflow(X,'ext');

%
% Display a histogram of cycle counts as a function of stress range.

histogram('BinEdges',edges','BinCounts',sum(hist,2))
xlabel('Stress Range')  
ylabel('Cycle Counts')

%
% Use rainflow without output arguments to display a histogram of cycles as a function of cycle average and cycle range.

rainflow(X,'ext')

% Copyright 2012 The MathWorks, Inc.