function [vecSigCl,vecSigClI,nSigCl,sSigCl] = findSigClu(vecCl,hCl) % IDENTIFY CLUSTERS IN OBSERVED DATA % This function identifies clusters in the observed data, based on the % given minimum length of consecutive points. It also counts the number % of clusters and returns the size of each identified cluster % convert cluster vector into cluster index vextor vecClI = vecCl; vecClI(vecCl~=0) = 1; % count number of all clusters in vector vecClIs = [0,vecClI]; % add 0 at start to make sure possible cluster starting at point 1 is considered vecClIe = [vecClI,0]; % add 0 at the end to make sure possible cluster lasting until the end is considered startCl = find(diff(vecClIs)==1); % find all points where difference vector is 1 (starting points of clusters in original vector) endCl = find(diff(vecClIe)==-1); % find all points where difference vector is -1 (ending points of clusters in original vector) nCl = numel(startCl); % return number of cluster starting points = number of clusters % replace non-significant clusters by 0s vecSigClI = vecClI; for cl = 1:nCl if hCl(cl)==0 vecSigClI(startCl(cl):endCl(cl)) = 0; end end % create vector that contains only significant clusters vecSigCl = vecCl.*vecSigClI; % count number of significant clusters in vector vecSigClIs = [0,vecSigClI]; % add 0 at start to make sure possible cluster starting at point 1 is considered vecSigClIe = [vecSigClI,0]; % add 0 at the end to make sure possible cluster lasting until the end is considered startSigCl = find(diff(vecSigClIs)==1); % find all points where difference vector is 1 (starting points of clusters in original vector) endSigCl = find(diff(vecSigClIe)==-1); % find all points where difference vector is -1 (ending points of clusters in original vector) nSigCl = numel(startSigCl); % return number of cluster starting points = number of clusters % calculate size of each cluster sSigCl = zeros(nSigCl,1); for c = 1:nSigCl sSigCl(c) = sum(vecSigCl(startSigCl(c):endSigCl(c))); % calulate size of each identified cluster end end