MATLAB: Finding durations between 1’s in a matrix

durationMATLABmatrix

I am creating a matrix of ones
I = binornd(1,a,T(j),n);
What i need to find next is the durations between the 1 values for each column, that is to say that for each column i will need a vector with the durations between values of 1 in the columns of the matrix.
the duration is simply the difference between the occurences, so for example if there is a 1 in (1,1) of the matrix and (3,1). Then the first number in the duration vector would be 3-1=2
Thanks! I am trying to avoid doing a for loop on this (in part because i want to get better at avoiding them in general!)

Best Answer

In the end i decided on just using a double for loop with an if statement, if anyone comes up with something elegant that would be great too. In case any one finds the post later on here is the code
for k=1:n
dcounter = 1;
for l=1:T(j)
if I(l,k)==1;
tempd(dcounter) = l;
dcounter=dcounter+1;
end
end
d{k} = diff(tempd);
end
Thank you for your time guys :)