Why does STRCAT function ignore trailing white spaces in MATLAB?
19 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
Réponse acceptée
MathWorks Support Team
le 27 Juin 2009
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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!