A ,ore efficient version of the loop:
nb = numel(b) - 1;
counts = zeros(1, nb);
for i = 1:nb
counts(i) = sum(tof >= b(i) & tof < b(i+1));
Is tof a scalar or a vector? Is b sorted? Are you looking for histcounts ?
Pre-allocation is essential, because letting an array grow iteratively is extremely expensive.