Skip to content

Instantly share code, notes, and snippets.

@tinybike
Created September 1, 2014 05:18
Show Gist options
  • Save tinybike/d8a26fd50b276908d4d5 to your computer and use it in GitHub Desktop.
Save tinybike/d8a26fd50b276908d4d5 to your computer and use it in GitHub Desktop.
insert commas into numbers for display
function comma_N = commatic(N)
% COMMATIC Insert commas into integers, e.g. 1234567 -> '1,234,567'.
% (c) Jack Peterson, 4/29/2013
N = num2str(N);
num_digits = length(N);
comma_N = '';
for j = 1:num_digits
comma_N = strcat(N(num_digits-j+1),comma_N);
if ~mod(j,3)
comma_N = strcat(',',comma_N);
end
end
if strcmp(comma_N(1), ',')
comma_N(1) = [];
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment