function s = AddCommas(n)
% n is a positive integer
% s is a string encoding of n with commas every 3rd decimal place.
% Thus, 1234567 produces '1,234,567'

r = num2str(n);
s = [];
i = 0;
for k=length(r):-1:1
i = i+1;
s = [r(k) s];
if rem(i,3)==0 && k~=1
s = [',' s];
end
end