ABSTRACT

You cannot control the field width or precision with a variable as you can in the C printf or fprintf, but string concatenation along with sprintf or num2str can help here. Try:

for n = 1:16

s = num2str(n) ;

s = [’%2d digits: %.’ s ’g\n’] ;

fprintf(s, n, pi) ;

end

23 Cell Publishing Cell publishing creates nicely formatted reports of MATLAB code, Command Window text output, figures, and graphics in HTML, LaTeX, PDF, or XML.