필터 지우기
필터 지우기

the 'fprintf' problem

조회 수: 4 (최근 30일)
dcydhb dcydhb
dcydhb dcydhb 2019년 5월 15일
댓글: dcydhb dcydhb 2019년 5월 15일
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

채택된 답변

Jan
Jan 2019년 5월 15일
편집: Jan 2019년 5월 15일
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
dcydhb dcydhb
dcydhb dcydhb 2019년 5월 15일
thanks a lot!!!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

제품


릴리스

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by