Why there is no space after the equal sign? (fprintf)
10 次查看(过去 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!