How can I concatenate strings in a cell array with spaces between them in MATLAB?

后端 未结 5 740
青春惊慌失措
青春惊慌失措 2020-12-15 23:34

I want to concatenate (padding with spaces) the strings in a cell array {\'a\', \'b\'} to give a single string \'a b\'. How can I do this in MATLAB

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-16 00:08

    matlab have a function to do this,

    ref:

    strjoin

    http://www.mathworks.com/help/matlab/ref/strjoin.html

    strjoin

    Join strings in cell array into single string

    Syntax

    str = strjoin(C) example
    
    str = strjoin(C,delimiter)
    

    Ex:

    Join List of Words with Whitespace

    Join individual strings in a cell array of strings, C, with a single space.

    C = {'one','two','three'};
    
    str = strjoin(C)
    
    str =
    
    one two three
    

提交回复
热议问题