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

5 views (last 30 days)
fprintf('%s \n',strcat('s',' = ','1000',';'));
Output:
s =1000;
Desired:
s = 1000;

Accepted Answer

Stephen23
Stephen23 on 7 Jun 2018
Edited: Stephen23 on 7 Jun 2018
"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.

More Answers (1)

Kodavati Mahendra
Kodavati Mahendra on 7 Jun 2018
Edited: Kodavati Mahendra on 7 Jun 2018
fprintf('%s \n',strcat("s"," = ","1000",";"));
output
s = 1000;

Categories

Find more on Characters and Strings in Help Center and File Exchange

Tags

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!