Home > wafo > cycles > nt2cmat.m

# nt2cmat

## PURPOSE

Calculates a cycle matrix from a counting distribution.

## SYNOPSIS

F = nt2cmat(NT,def)

## DESCRIPTION

```  NT2CMAT  Calculates a cycle matrix from a counting distribution.

CALL:  F = nt2cmat(NT,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:
F0 = round(triu(rand(4),1)*10)
NT = cmat2nt(F0)
F = nt2cmat(NT)

## CROSS-REFERENCE INFORMATION

This function calls:
 error Display message and abort function. num2str Convert number to string. (Fast version)
This function is called by:
 lc2rfmextreme Compute extreme RFM from level crossings. mctp2tc Frequencies of upcrossing troughs and crests using Markov chain of turning points. test_cycles Quick test of the routines in module 'cycles'

## SOURCE CODE

```001 function F = nt2cmat(NT,def)
002 % NT2CMAT  Calculates a cycle matrix from a counting distribution.
003 %
004 % CALL:  F = nt2cmat(NT,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 %   F0 = round(triu(rand(4),1)*10)
018 %   NT = cmat2nt(F0)
019 %   F = nt2cmat(NT)
020 %
022
023 % Tested on Matlab 6.0
024 %
025 % History:
026 % Revised by PJ 18-May-2000
027 %   Updated help text.
028 % Created by PJ (Pär Johannesson) 23-Nov-1999
029 % Earlier version named 'nt2fr' in WAT
030
031 % Check input arguments
032
033 ni = nargin;
034 no = nargout;
035 error(nargchk(1,2,ni));
036
037 if ni<2
038   def = 1;
039 end
040
041 n=length(NT); % Number of discrete levels
042
043 if def == 1
044
045   F = zeros(n);
046   I=1:n-1;
047   J=2:n;
048   F(I,J) = NT(I+1,J-1)-NT(I,J-1)-NT(I+1,J)+NT(I,J);
049
050 elseif def == 11 % same as def=1 but using for-loop
051
052   F = zeros(n);
053   for i = 1:n-1
054     for j= 2:n
055       F(i,j) = NT(i+1,j-1)-NT(i,j-1)-NT(i+1,j)+NT(i,j);
056     end
057   end
058
059 elseif def == 0
060
061   disp(['def = ' num2str(def) ' not yet implemented'])
062
063 elseif def == -1
064
065   disp(['def = ' num2str(def) ' not yet implemented'])
066
067 else
068
069   disp(['def = ' num2str(def) ': not a valid value of def'])
070
071 end
072```

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