admin 管理员组

文章数量: 887031


2024年1月5日发(作者:dubbo长连接和短连接的区别)

fprintf :: Functions (MATLAB®)jar:file:///C:/Program%20Files/MATLAB/R2011a/help/techdoc/!/...fprintfWrite data to text fileSyntaxfprintf(fileID, format, A, ...)fprintf(format, A, ...)count = fprintf(...)fprintf输出是一列一列的从左到右输出。Descriptionfprintf(fileID, format, A, ...) applies the format to all elements of array A and any

additional array arguments in column order, and writes the data to a text file. fprintf uses theencoding scheme specified in the call to f(format, A, ...) formats data and displays the results on the = fprintf(...) returns the number of bytes that fprintf ArgumentsfileIDOne of the following:An integer file identifier obtained from fopen.1 for standard output (the screen).2 for standard t: 1 (the screen)formatString in single quotation marks that describes the format of the outputfields. Can include combinations of the following:Percent sign followed by a conversion character, such as '%s' for

ors that describe field width, precision, and other l text to characters, including:''Single quotation mark%%

Percent characterabfnBackslashAlarmBackspaceForm feedNew line1 of 72012-3-22 21:18

fprintf :: Functions (MATLAB®)jar:file:///C:/Program%20Files/MATLAB/R2011a/help/techdoc/!/...rtvCarriage returnHorizontal tabVertical tabxNHexadecimal number, NN标识符Octal number, N8进制Conversion characters and optional operators appear in the following order(includes spaces for clarity):字段宽度The following table lists the available conversion characters and TypeInteger, signedConversion%d or %i%ld or %li%hd or %hiInteger, unsigned%u%o%xDetailsBase 10 values64-bit base 10 values16-bit base 10 valuesBase 10Base 8 (octal)Base 16 (hexadecimal), lowercase

letters a–fSame as %x, uppercase lettersA–F64-bit values, base 10, 8, or 16%X%lu%lo%lx or %lX%hu%ho16-bit values, base 10, 8, or 162 of 72012-3-22 21:18

fprintf :: Functions (MATLAB®)jar:file:///C:/Program%20Files/MATLAB/R2011a/help/techdoc/!/...Value TypeConversion%hx or %hXDetails定点数表示法Fixed-point notationExponential notation, such as

3.141593e+00Same as %e, but uppercase, such

as 3.141593E+00The more compact of %e or %f,with no trailing zerosThe more compact of %E or %f,with no trailing zerosDouble-precision hexadecimal,

octal, or decimal valueExample: %bx prints pi as

400921fb54442d18Single-precision hexadecimal,

octal, or decimal valueExample: %tx prints pi as

40490fdbSingle characterString of charactersFloating-point

number大写指数计数法%f%e%E%g尾随零丗你标注的时候 比如5.5 你的公差精度是2位的画 就显示为5.50 你移除了尾随零值 不管你的公差精度是多少 都显示为5.5 就是这个意思

%G%bx or %bX%bo%bu%tx or %tX%to%tuCharacters%c%sAdditional operators include:Field widthMinimum number of characters to print. Can be a number, or anasterisk (*) to refer to an argument in the input list. For example, theinput list ('%12d', intmax) is equivalent to ('%*d', 12,

intmax).PrecisionFor %f, %e, or %E:Number of digits to the right of the decimal

point.打印的最小的字符数3 of 72012-3-22 21:18

fprintf :: Functions (MATLAB®)jar:file:///C:/Program%20Files/MATLAB/R2011a/help/techdoc/!/...Example: '%6.4f' prints pi as '3.1416'For %g or %GNumber of significant e: '%6.4g' prints pi as ' 3.142'Can be a number, or an asterisk (*) to refer to an argument in theinput list. For example, the input list ('%6.4f', pi) is equivalent to

('%*.*f', 6, 4, pi).小数点后第4位四Flags舍五入左侧齐行 sign character (+ or –).Insert a space before the '–''+'' ''0'Example%-5.2f%+5.2f% 5.2f%05.2f%#5.0f填塞Pad with zeros.'#'Modify selected numeric conversions:For %o, %x, or %X, print 0, 0x, or %f, %e, or %E, print decimal point

even when precision is %g or %G, do not remove trailingzeros or decimal fierOrder for processing inputs. Use the syntax n$, where n represents

the position of the value in the input example, '%3$s %2$s %1$s %2$s' prints inputs 'A', 'B',

'C' as follows: C B A following limitations apply to conversions:Numeric conversions print only the real component of you apply an integer or string conversion to a numeric value thatcontains a fraction, MATLAB overrides the specified conversion, anduses % you apply a string conversion (%s) to integer values, MATLABconverts values that correspond to valid character codes tocharacters. For example, '%s' converts [65 66 67] to ent platforms display exponential notation (such as %e) with a

different number of digits in the exponent.4 of 72012-3-22 21:18

fprintf :: Functions (MATLAB®)jar:file:///C:/Program%20Files/MATLAB/R2011a/help/techdoc/!/...PlatformWindowsUNIXExample1.23e+0041.23e+04Different platforms display negative zero (-0) differently.

PlatformWindowsOthers%e or %EConversion Character%f%g or %G0-00.000000e+0000.000000-0.000000e+00-0.000000ANumeric or character esPrint multiple values and literal text to the screen:B = [8.8 7.7 ; ... 8800 7700];fprintf('X is %4.2f meters or %8.3f mmn', 9.9, 9900, B)MATLAB displays:X is 9.90 meters or 9900.000 mmX is 8.80 meters or 8800.000 mmX is 7.70 meters or 7700.000 mm输入上述字符丆换行输入另外一行。

Write a short table of the exponential function to a text file called :x = 0:.1:1;y = [x; exp(x)];% open the file with write permissionfid = fopen('', 'w');fprintf(fid, '%6.2f %12.8fn', y);fclose(fid);% view the contents of the file输出结果丗135%应该是表示一个元素5 of 72012-3-22 21:18

fprintf :: Functions (MATLAB®)jar:file:///C:/Program%20Files/MATLAB/R2011a/help/techdoc/!/...type LAB import functions, all UNIX applications, and Microsoft Word and WordPad recognize'n' as a newline indicator. However, if you plan to read the file with Microsoft Notepad, use'rn' to move to a new line when writing. For example, replace the previous call to fprintfwith the following:fprintf(fid, '%6.2f %12.8frn', y);

Display a hyperlink (The MathWorks Web Site) on the screen:site = '';title = 'The MathWorks Web Site';fprintf('%sn', site, title)References[1] Kernighan, B. W., and D. M. Ritchie, The C Programming Language, Second Edition,

Prentice-Hall, Inc., 1988.[2] ANSI specification X3.159-1989: "Programming Language C," ANSI, 1430 Broadway, NewYork, NY Alsodisp | fclose | ferror | fopen | fread | fscanf | fseek | ftell | fwrite | sprintfHow ToFormatting StringsAppending or Overwriting Existing Files6 of 72012-3-22 21:18

fprintf :: Functions (MATLAB®)jar:file:///C:/Program%20Files/MATLAB/R2011a/help/techdoc/!/...

Was this topic helpful?

Yes

No

© 1984-2011 The MathWorks, Inc.

• Terms of Use

• Patents

• Trademarks

• Acknowledgments7 of 72012-3-22 21:18


本文标签: 连接 应该 字符 输入