Home > data-analysis > stats > cevent > cevent_transition_matrix.m

cevent_transition_matrix

PURPOSE ^

cevent_transition_matrix Generate a transition matrix of the input cevent.

SYNOPSIS ^

function matrix = cevent_transition_matrix(cevent, max_gap, category_num)

DESCRIPTION ^

 cevent_transition_matrix   Generate a transition matrix of the input cevent.

 matrix =  cevent_transition_matrix(cevent, max_gap);
    matrix:   the transition matrix, where matrix(i, j) is the count of 
                the transitions between cevent value i to cevent value j.
    cevent:   cevent data
    max_gap:  the maximum gap (in second) between two intervals that will be
              counted as a transition. The default value of "max_gap" is Inf.
    category_num: The number of category for this cevent. The default
                  is the largest event value found in the input "cevent".
 Example :
 > cevent_data = [69.0280   69.9450    1.0000;
                72.5080   73.8050     4.0000;
                75.4820   87.1540     1.0000;
                91.3940  104.1530     4.0000;
                108.3860  111.1130    4.0000;
                103.1310  121.1620    1.0000;
                122.7510  123.5740    1.0000;                      
                150.0210  153.8760    4.0000;
                154.0310  155.9760    1.0000]
 
 > matrix =  cevent_transition_matrix(cevent_data)
 
 matrix =
 
      1     0     0     3
      0     0     0     0
      0     0     0     0
      3     0     0     1
 
 > matrix =  cevent_transition_matrix(cevent_data, 5)
  
 matrix =
 
      1     0     0     2
      0     0     0     0
      0     0     0     0
      3     0     0     1
  
 > matrix =  cevent_transition_matrix(cevent_data,5, 6)
 
 matrix =
 
      1     0     0     2     0     0
      0     0     0     0     0     0
      0     0     0     0     0     0
      3     0     0     1     0     0
      0     0     0     0     0     0
      0     0     0     0     0     0

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function matrix = cevent_transition_matrix(cevent, max_gap, category_num)
0002 % cevent_transition_matrix   Generate a transition matrix of the input cevent.
0003 %
0004 % matrix =  cevent_transition_matrix(cevent, max_gap);
0005 %    matrix:   the transition matrix, where matrix(i, j) is the count of
0006 %                the transitions between cevent value i to cevent value j.
0007 %    cevent:   cevent data
0008 %    max_gap:  the maximum gap (in second) between two intervals that will be
0009 %              counted as a transition. The default value of "max_gap" is Inf.
0010 %    category_num: The number of category for this cevent. The default
0011 %                  is the largest event value found in the input "cevent".
0012 % Example :
0013 % > cevent_data = [69.0280   69.9450    1.0000;
0014 %                72.5080   73.8050     4.0000;
0015 %                75.4820   87.1540     1.0000;
0016 %                91.3940  104.1530     4.0000;
0017 %                108.3860  111.1130    4.0000;
0018 %                103.1310  121.1620    1.0000;
0019 %                122.7510  123.5740    1.0000;
0020 %                150.0210  153.8760    4.0000;
0021 %                154.0310  155.9760    1.0000]
0022 %
0023 % > matrix =  cevent_transition_matrix(cevent_data)
0024 %
0025 % matrix =
0026 %
0027 %      1     0     0     3
0028 %      0     0     0     0
0029 %      0     0     0     0
0030 %      3     0     0     1
0031 %
0032 % > matrix =  cevent_transition_matrix(cevent_data, 5)
0033 %
0034 % matrix =
0035 %
0036 %      1     0     0     2
0037 %      0     0     0     0
0038 %      0     0     0     0
0039 %      3     0     0     1
0040 %
0041 % > matrix =  cevent_transition_matrix(cevent_data,5, 6)
0042 %
0043 % matrix =
0044 %
0045 %      1     0     0     2     0     0
0046 %      0     0     0     0     0     0
0047 %      0     0     0     0     0     0
0048 %      3     0     0     1     0     0
0049 %      0     0     0     0     0     0
0050 %      0     0     0     0     0     0
0051 %
0052 
0053 if ~exist('max_gap', 'var')
0054     max_gap = Inf;
0055 end
0056 data = cevent(:,3);
0057 
0058 if ~exist('category_num', 'var')
0059     category_num = max(data);
0060 end
0061 
0062 matrix = zeros(category_num, category_num);
0063 for i=2:length(data)
0064     if cevent(i, 1) - cevent(i-1, 2) <= max_gap  % The gap between two events shouldn't be larger than max_gap
0065         matrix(data(i-1),data(i)) = matrix(data(i-1),data(i)) + 1;
0066     end
0067 end
0068 
0069 end

Generated on Wed 24-May-2017 00:00:56 by m2html © 2005