Why does STRCAT function ignore trailing white spaces in MATLAB?

20 visualizaciones (últimos 30 días)
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

Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 27 de Jun. de 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))

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by