Home > wafo > cycles > cmat2nt.m

# cmat2nt

## PURPOSE Calculates a counting distribution from a cycle matrix.

## SYNOPSIS NT = cmat2nt(F,def)

## DESCRIPTION ```  CMAT2NT Calculates a counting distribution from a cycle matrix.

CALL:  NT = cmat2nt(F,def);

NT       = Counting distribution. [nxn]

F        = Cycle matrix. [nxn]
def      =  1: causes peaks to be projected upwards and troughs
downwards to the closest discrete level (default).
=  0: causes peaks and troughs to be projected to
the closest discrete level.
= -1: causes peaks to be projected downwards and the
troughs upwards to the closest discrete level.

Example:
F = round(triu(rand(4),1)*10)
NT = cmat2nt(F)

See also  nt2cmat```

## CROSS-REFERENCE INFORMATION This function calls:
 error Display message and abort function. num2str Convert number to string. (Fast version)
This function is called by:
 cmat2lc Calculates the level crossings from a cycle matrix. lc2rfmextreme Compute extreme RFM from level crossings. mctp2tc Frequencies of upcrossing troughs and crests using Markov chain of turning points. smc2rfm Calculates the rainflow matrix/intensity for a switching Markov chain. smctp2rfm Calculates the rainflow matrix for a SMCTP. test_cycles Quick test of the routines in module 'cycles'

## SOURCE CODE ```001 function NT = cmat2nt(F,def)
002 % CMAT2NT Calculates a counting distribution from a cycle matrix.
003 %
004 % CALL:  NT = cmat2nt(F,def);
005 %
006 %   NT       = Counting distribution. [nxn]
007 %
008 %   F        = Cycle matrix. [nxn]
009 %   def      =  1: causes peaks to be projected upwards and troughs
010 %                  downwards to the closest discrete level (default).
011 %            =  0: causes peaks and troughs to be projected to
012 %                  the closest discrete level.
013 %            = -1: causes peaks to be projected downwards and the
014 %                  troughs upwards to the closest discrete level.
015 %
016 % Example:
017 %   F = round(triu(rand(4),1)*10)
018 %   NT = cmat2nt(F)
019 %
020 % See also  nt2cmat
021
022 % Tested on Matlab 6.0
023 %
024 % History:
025 % Created by PJ (Pär Johannesson) 19-Nov-1999
026 % Earlier version named 'nt2fr' in WAT
027
028 % Check input arguments
029
030 ni = nargin;
031 no = nargout;
032 error(nargchk(1,2,ni));
033
034 if ni<2
035   def = 1;
036 end
037
038 n=length(F); % Number of discrete levels
039
040 if def == 1
041
042   NT = zeros(n);
043   NT(2:n,1:n-1) = fliplr(cumsum(fliplr(cumsum(F(1:end-1,2:end))),2));
044
045 elseif def == 11 % same as def=1 but using for-loop
046
047   NT = zeros(n);
048   for i = 2:n
049     for j= 1:n-1
050       NT(i,j) = sum(sum(F(1:i-1,j+1:n)));
051     end
052   end
053
054 elseif def == 0
055
056   disp(['def = ' num2str(def) ' not yet implemented'])
057
058 elseif def == -1
059
060   disp(['def = ' num2str(def) ' not yet implemented'])
061
062 else
063
064   disp(['def = ' num2str(def) ': not a valid value of def'])
065
066 end
067
068
069
070```

Mathematical Statistics
Centre for Mathematical Sciences
Lund University with Lund Institute of Technology

Comments or corrections to the WAFO group

Generated on Thu 06-Oct-2005 02:21:16 for WAFO by m2html © 2003