The function sprintf does take some getting used to, and you should read up on i
ID: 3884936 • Letter: T
Question
The function sprintf does take some getting used to, and you should read up on its various options. Construct a string that combines characters and numbers. You are giving a database with birthdays, and you are pulling from it the information to construct the string that must read exactly 'Chriss birthday is May 30'. % Do not change the lines below, keep the database intact bdays = struct('Name', {'Chris ', 'Luke' > 'DD', {30 30}, 'MM', {05 12}, 'YYYY', {1974 1975}): % Do not change the lines below, I want to see a specific result! nnr = 1: bdayn = bdays(nnr) .Name: bdayd = bdays(nnr) .DD: bdaym = bdays(nnr) .MM: % Do not change the line below, but do inspect the result bdayms = datestr(datenum(0, bdaym, 1) 3): % Now use format descriptors '%s' and '%i', and the variables % bdayn, bdayms and bdayd to complete the line below such that it reads EXACTLY: % 'Chriss birthday is May 30' v = sprintf(' birthday is', );Explanation / Answer
The precision field in a formatting operator is a nonnegative integer that immediately follows a period. For example, in the operator %7.3f, the precision is 3. For the %g operator, the precision indicates the number of significant digits to display. For the %f, %e, and %E operators, the precision indicates how many digits to display to the right of the decimal point.
Display numbers to different precisions using the precision field.
While you can specify the precision in a formatting operator for input text (for example, in the %s operator), there is usually no reason to do so. If you specify the precision as p, and pis less than the number of characters in the input text, then the output contains only the first p characters.
Field Width
The field width in a formatting operator is a nonnegative integer that specifies the number of digits or characters in the output when formatting input values. For example, in the operator %7.3f, the field width is 7.
Specify different field widths. To show the width for each output,
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.