Why does STRCAT function ignore trailing white spaces in MATLAB?

14 ビュー (過去 30 日間)
MathWorks Support Team
MathWorks Support Team 2009 年 6 月 27 日
When I execute the following:
a=10;
strcat('a = ',num2str(a))
I receive the following answer:
ans =
a =10
The space after the equal sign is missing. No matter how many spaces you insert the result is always:
a =10

採用された回答

MathWorks Support Team
MathWorks Support Team 2009 年 6 月 27 日
The ability to preserve trailing spaces in character array inputs is not available in MATLAB, this is mentioned in the documentation of the STRCAT function:
“Trailing spaces in character array inputs are ignored and do not appear in the output. This is not true for inputs that are cell arrays of strings. Use the concatenation syntax [s1 s2 s3 ...] to preserve trailing spaces.”
To work around this issue, either use :
a=10;
['a = ', num2str(a)]
or
c={' = '};
strcat('a', c, num2str(a))

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by