Hello,
I have a 121x97x51135 matrix of 1's and 0's which flag certain periods of time. I would like to produce new variables that count the number of times a 1 is followed by another in the subsequent element, and another if two ones follow in the subsequent 2 elements.
For instance:
if
A(:,:,1) = ones(3,3,1);A(:,:,2) = ones(3,3,1);A(:,:,3) = zeros(3,3,1);A(:,:,4) = ones(3,3,1);
The output variable for the first test (1 followed by 1) would be a 3×3 matrix with a count of the number of times that occurred in A and thus result = ones(3,3).
Any suggestions how to do this with out a loop? Not sure if a function out there works for this. I tried diff() but diff won't work in terms of adding up these times. For instance:
diff(A,[],3)ans(:,:,1) = 0 0 0 0 0 0 0 0 0ans(:,:,2) = -1 -1 -1 -1 -1 -1 -1 -1 -1ans(:,:,3) = 1 1 1 1 1 1 1 1 1
Thanks in advance!
Best Answer