Search code examples
matlabconcatenationstring-concatenation

Possible to concatenate words and number into a single string in Matlab?


I am wondering if it is possible in matlab to put together words and number into a single non blank string.

For example:

a = 160727
b = 'skippy'       
c = 42

I want this to be written as: 

160727_skippy_42

Is this possible in matlab?


Solution

  • Another way is to use sprintf:

    s = sprintf('%d_%s_%d', a, b, c)
    

    or, depending on the context, you might prefer

    s = sprintf('%d_skippy_%d', a, c)