www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/PrintLiteralTextandArrayValuesExample.m

    %% Print Literal Text and Array Values  
% Print multiple numeric values and literal text to the screen.   

% Copyright 2015 The MathWorks, Inc.


%%  
A1 = [9.9, 9900];
A2 = [8.8,  7.7 ; ...
      8800, 7700];
formatSpec = 'X is %4.2f meters or %8.3f mm\n';
fprintf(formatSpec,A1,A2) 

%%
% |%4.2f| in the |formatSpec| input specifies that the first value in each
% line of output is a floating-point number with a field width of four digits,
% including two digits after the decimal point. |%8.3f| in the |formatSpec|
% input specifies that the second value in each line of output is a floating-point
% number with a field width of eight digits, including three digits after
% the decimal point. |\n| is a control character that starts a new line.