Strings‎ > ‎

Join

Concatenate strings of a cell array


S = { 'A','B','C' }   % create horizontal cell array
  'A' 'B' 'C'
strjoin(S,'') % concatenate strings using strjoin()  (recommended, available with version: R2016b)
  ABC

strcat(S{:})  % concatenate strings using strcat()
  ABC

cell2mat(S)  % concatenate strings using cell2mat()
  ABC

['A','B','C']  % simple array
  ABC

How to add a comma or space between concatenated strings?


S = { 'A','B','C' }

strjoin(S,',')
  A,B,C

strjoin(S) % default: space between strings
  A B C



using strcat()  (not recommended for Matlab versions > R2016b)
strcat( cell2mat(strcat(S(1:end-1)',{','})'), S{end} )
  A,B,C

steps explained

1) add comma to each string
strcat(S',{','})
    'A,'
    'B,'
    'C,'

2) concatenate strings (cell2mat is used to covert string from cell-array into plain char)
cell2mat(strcat(S',{','})')
  A,B,C,

3) for only adding the comma between strings, we need add the last string without comma
strcat( cell2mat(strcat(S(1:end-1)',{','})'), S{end} )
  A,B,C