Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String concatenation with spaces

I would like to concatenate strings. I tried using strcat:

x = 5;
m = strcat('is', num2str(x)) 

but this function removes trailing white-space characters from each string. Is there another MATLAB function to perform string concatenation which maintains trailing white-space?

like image 274
lola Avatar asked Apr 30 '12 09:04

lola


1 Answers

You can use horzcat instead of strcat:

>> strcat('one ','two')
ans =
onetwo
>> horzcat('one ','two')
ans =
one two

Alternatively, if you're going to be substituting numbers into strings, it might be better to use sprintf:

>> x = 5;
>> sprintf('is %d',x)
ans =
is 5
like image 159
Chris Taylor Avatar answered Oct 21 '22 23:10

Chris Taylor