Code covered by the BSD License  

Highlights from

5.0 | 4 ratings Rate this file 62 Downloads (last 30 days) File Size: 2.61 KB File ID: #31862 Version: 1.1



Kota Yamaguchi (view profile)


18 Jun 2011 (Updated )

Concatenate an array into a single string.

| Watch this File

File Information

    S = strjoin(C)
    S = strjoin(C, separator)
    S = strjoin(C) takes an array C and returns a string S which
    concatenates array elements with comma. C can be a cell array
    of strings, a character array, or a numeric array. If C is a
    matrix, it is first flattened to get an array and concateneted.
    S = strjoin(C, separator) also specifies separator to be used
    for string concatenation. The default separator is comma.
    >> str = strjoin({'this','is','a','cell','array'})
    str =
    >> str = strjoin(char({'this','is','a','char','array'}))
    str =
    >> str = strjoin([1,2,2],'_')
    str =
    >> str = strjoin({1,2,2,'string'},'\t')
    str =
    1 2 2 string

MATLAB release MATLAB 7.12 (R2011a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (5)
07 Apr 2014 Julian Hapke

Thanks! It's even faster than the newly introduced build-in strjoin (at least the 2013a-Version I tested with a 1x100000 cell array of strings)


>> a=cell(1,100000);[a{:}] = deal('bla');
>> b=nan;tic;for ii =1:10;b=strjoin(a,' ');end;toc;
Elapsed time is 5.018935 seconds.
>> b=nan;tic;for ii =1:10;b=strjoin2(a,' ');end;toc;
Elapsed time is 0.424864 seconds.

where strjoin2 is the one I'm commenting on

21 Mar 2013 Ying Yin

Thank you, Kota! I was about to write one myself too because I'm used to the join method in Ruby, but found yours. Nicely done!

Comment only
21 Mar 2013 Ying Yin  
21 Mar 2013 Ying Yin  
25 Jul 2012 Robert Moss

Very nicely done! I was about to write this myself, but this has saved me the effort. I like the way it handles arrays and cellstr arrays.

I'm curious: do you happen to be an IDL programmer? There is an IDL function of the same name with the "same" functionality.

22 Apr 2013 1.1

Added BSD licence statement; Improved efficiency;

Contact us