function out=legTrackerMarkovMat(data,varargin) %legTrackerMarkovMat uses the vector of KNN classification labels to %populate a variety of transition Markov Matrices. %Usage: %out=legTrackerMarkovMat(data,varargin) %data = vector of classification labels {0 ... 11} %varargin = 2 parameter options variable %varargin{1} = 'pie' or 1 or other/NA %varargin{2} = 1 or other/NA % * legTrackerMarkovMat(data, 'pie') returns a 12x1 vector of the percent % labels in data that are each behavioral label. % * legTrackerMarkovMat(data, 1, ?) sets the diagonal of the transition % Markov Matrix to 0. % * legTrackerMarkovMat(data, ?, 1) normalizes the sum of the rows of the % transition Markov Matrix to 1. %allocate output in memory out=zeros(12,12); %for all frame transitions for i=1:size(data,1)-1 %increment Markov Matrix entry for particular transition out(data(i)+1,data(i+1)+1)=out(data(i)+1,data(i+1)+1)+1; end %if there are varargin parameters if ~isempty(varargin) % calculate the percent of labels in the vector of each time i.e. the % piechart of time spent in each behavioral mode if isequal(varargin{1},'pie') out=zeros(12,1); for i=0:11 out(i+1)=sum(data==i); end else %if varargin{1}==1 set the diagonal of the matrix to 0s. if varargin{1}==1 out(logical(eye(size(out,1))))=0; end %if varargin{2}==1 normalize so that the sum of each row is 1. if varargin{2}==1 out=out./repmat(sum(out,2),1,12); out(isnan(out))=0; end end end