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

4 ビュー (過去 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 件のコメント
Akbar
Akbar 2018 年 6 月 7 日
Thanks for the answer.

サインインしてコメントする。

その他の回答 (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 Center および File ExchangeCharacters and Strings についてさらに検索

タグ

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by