필터 지우기
필터 지우기

Why there is no space after the equal sign? (fprintf)

조회 수: 3 (최근 30일)
Akbar
Akbar 2018년 6월 7일
편집: Akbar 2018년 6월 7일
fprintf('%s \n',strcat('s',' = ','1000',';'));
Output:
s =1000;
Desired:
s = 1000;

채택된 답변

Stephen23
Stephen23 2018년 6월 7일
편집: Stephen23 2018년 6월 7일
"Why there is no space after the equal sign?"
It has nothing to do with fprintf. As the strcat clearly states, strcat removes whitespace characters from the end of char vectors: "For character array inputs, strcat removes trailing ASCII white-space characters". If you want to keep the space characters, put it into a scalar cell array, like this:
{' = '}
But really you would be much better off just writing a proper format string for fprintf, rather than using both strcat and fprintf.

추가 답변 (1개)

Kodavati Mahendra
Kodavati Mahendra 2018년 6월 7일
편집: Kodavati Mahendra 2018년 6월 7일
fprintf('%s \n',strcat("s"," = ","1000",";"));
output
s = 1000;
  댓글 수: 1
Akbar
Akbar 2018년 6월 7일
편집: Akbar 2018년 6월 7일
Thank you, Kodavati!

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

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by