Try to do this without loops.
%
array = randi([0 1], [15 15 2200]);
%
[n1,n2,n3] = size(array);
%
array2d = reshape(array,[],n3)';
%
array2d = [zeros(1,n1*n2);array2d;zeros(1,n1*n2)];
%
arrayDiff = diff(array2d,1,1);
[startIdx,startCol] = find(arrayDiff==1);
[endIdx,endCol] = find(arrayDiff==-1);
%
%
persistence = endIdx-startIdx; %
%
nBins = 20;
figure,hist(persistence,nBins)
Edit:
To see another visual representation of saving your tracks, call
figure,imshow(array2d)
It shows white bars wherever you have a sequence of links, and it will show you common patterns.
Jonas source
share