Programming Fundamentals - The MathWorks - #151

/ 840


catalogue search
P. 151
P. 152
P. 153
P. 154
P. 155
P. 156
P. 157
P. 158
P. 159
P. 160
P. 161
P. 162
P. 163
P. 164
P. 165
P. 166
P. 167
P. 168
P. 169
P. 170
P. 171
P. 172
P. 173
P. 174
P. 175
P. 176
P. 177
P. 178
P. 179
P. 180
P. 181
P. 182
P. 183
P. 184
P. 185
P. 186
P. 187
P. 188
P. 189
P. 190
P. 191
P. 192
P. 193
P. 194
P. 195
P. 196
P. 197
P. 198
P. 199
P. 200


See other catalogues for The MathWorks

Text version of the page
Characters and Strings
The general formatting syntax for these functions is
functionname(..., format_string, value1, value2, valueN)
where the format_string argument expresses the basic content and formatting of the final output string, and the value arguments that follow supply data values to be inserted into the string.
Here is a sample sprintf statement, also showing the resulting output string:
sprintf('The price of %s on %d/%d/%d was $%.2f.', ... 'bread', 7, 1, 2006, 2.49)
ans =
The price of bread on 7/1/2006 was $2.49. The following sections cover
• "The Format String" on page 2-47
• "Input Value Arguments" on page 2-48
• "The Formatting Operator" on page 2-50
• "Constructing the Formatting Operator" on page 2-50
• "Setting Field Width and Precision" on page 2-55
• "Restrictions for Using Identifiers" on page 2-58
Note The examples in this section of the documentation use only the sprintf function to demonstrate how string formatting works. However, you can run the examples using the fprintf, warning,and error functionsaswell.
The Format String
The first input argument in the sprintf statement shown above is the format string:
'The price of %s on %d/%d/%d was $%.2f.'
2-47

pageCatalog pdf di En 2012-06-22-01