Why there is no space after the equal sign? (fprintf)
조회 수: 3 (최근 30일)
이전 댓글 표시
fprintf('%s \n',strcat('s',' = ','1000',';'));
Output:
s =1000;
Desired:
s = 1000;
댓글 수: 0
채택된 답변
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
2018년 6월 7일
편집: Kodavati Mahendra
2018년 6월 7일
fprintf('%s \n',strcat("s"," = ","1000",";"));
output
s = 1000;
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!