格式化输出命令 fprintf,例子
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)
X is 9.90 meters or 9900.000 mm X is 8.80 meters or 8800.000 mm X is 7.70 meters or 7700.000 mm
根据matlab help文件
Value Type | Conversion | Details |
---|---|---|
Integer, signed 有符号整数 |
| Base 10 |
Integer, unsigned |
| Base 10 |
| Base 8 (octal) | |
| Base 16 (hexadecimal), lowercase letters | |
| Same as | |
Floating-point number 浮点数 |
| Fixed-point notation (Use a precision operator to specify the number of digits after the decimal point.) |
| Exponential notation, such as | |
| Same as | |
| The more compact of | |
| The more compact of | |
Characters or strings |
| Single character |
| Character vector or string array. The type of the output text is the same as the type of |
参考文献