MATLAB: Does STRCAT function ignore trailing white spaces in MATLAB

blankMATLABpreservespace

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

Best Answer

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))