Matlab strcat function troubles with spaces

stanigator picture stanigator · Sep 15, 2009 · Viewed 38.6k times · Source

I'm trying to accomplish this:

strcat('red ', 'yellow ', 'white ')

I expected to see "red yellow white", however, I see "redyellowwhite" on the command output. What needs to be done to ensure the spaces are concatenated properly? Thanks in advance.

Answer

nsanders picture nsanders · Sep 15, 2009

From the matlab help page for strcat:

"strcat ignores trailing ASCII white space characters and omits all such characters from the output. White space characters in ASCII are space, newline, carriage return, tab, vertical tab, or form-feed characters, all of which return a true response from the MATLAB isspace function. Use the concatenation syntax [s1 s2 s3 ...] to preserve trailing spaces. strcat does not ignore inputs that are cell arrays of strings. "