Borrar filtros
Borrar filtros

the 'fprintf' problem

4 visualizaciones (últimos 30 días)
dcydhb dcydhb
dcydhb dcydhb el 15 de Mayo de 2019
Comentada: dcydhb dcydhb el 15 de Mayo de 2019
codes are as this
name = 'Alice'; age = 12;
X = sprintf('%s will be %d this year.', name, age)
y= fprintf('%d will be %d this year.', 10, 10)
why the output is as this?
where the '24' come from?
results are as this
10 will be 10 this year.
y =
24

Respuesta aceptada

Jan
Jan el 15 de Mayo de 2019
Editada: Jan el 15 de Mayo de 2019
While sprintf replies the created string, the output of fprintf is the number of printed characters. In your case "10 will be 10 this year." contains 24 characters.
This is explained in the documentation, see:
doc fprintf
To be exact:
nbytes = fprintf(___) returns the number of bytes that fprintf writes,
using any of the input arguments in the preceding syntaxes.
"Bytes" mean the characters, if the output would be written to a file. Then each character uses 1 byte, althought internally the characters are stored with 2 bytes.
Rule of thumb: Whenever you have a question to a certain command, start with reading its documentation.
  1 comentario
dcydhb dcydhb
dcydhb dcydhb el 15 de Mayo de 2019
thanks a lot!!!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2014a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by