MATLAB: Print numeric array as list with commas

array

I cant figure out how to print a = 1:10 as 1,2,3,4,5,6,7,8,9,10

Best Answer

regexprep( mat2str(a), {'\[', '\]', '\s+'}, {'', '', ','})
or
[sprintf('%d,', a(1:end-1)), sprintf('%d', a(end))];
or
temp = sprintf('%d,', a);
temp(end) = []; %get rid of trailing comma