Date: Feb 2, 2013 4:41 AM
Author: Bruno Luong
Subject: Re: index end-point to matrix

Another method:

k = b > 0;
c = b(k);
l = diff([0 c]);
m = bsxfun(@le,(1:max(l))',l);
r = zeros(size(m));
r(m) = 1:c(end);
a = zeros(length(b), max(l));
a(k,:) = r'

% Bruno