The distance from the i-th point of T to the j-th centroid is
sqrt(sum((T(:,i) - centroids(:,j)).^2));
So, if that's the distance for one T point, from one centroid, you just need to loop over all points:
for i = 1:size(T,2)
for j = 1:size(centroids,2)
I don't think you need your other loop down the first dimension of T, because that is covered by the sum command above, which is vectorized.
That's a pretty big hint, so I hope that is enough to get you going.