Next: , Up: Creating Strings


5.3.1 Concatenating Strings

It has been shown above that strings can be concatenated using matrix notation (see Strings, Character Arrays). Apart from that, there are several functions to concatenate string objects: char, strvcat, strcat and cstrcat. In addition, the general purpose concatenation functions can be used: see cat, horzcat and vertcat.

— Built-in Function: char (x)
— Built-in Function: char (cell_array)
— Built-in Function: char (s1, s2, ...)

Create a string array from one or more numeric matrices, character matrices or cell arrays. For numerical input, each element is converted to the corresponding ASCII character. The arguments (and elements of cell array(s)) are concatenated vertically. The returned values are padded with blanks as needed to make each row of the string array have the same length. Empty strings are not removed. For example,

          char ([97, 98, 99], "", {"98", "99", 100}, ["num", "bers"])
               ⇒ ["abc    "
                  "       "
                  "98     "
                  "99     "
                  "d      "
                  "numbers"]

— Built-in Function: strvcat (x)
— Built-in Function: strvcat (cell_array)
— Built-in Function: strvcat (s1, s2, ...)

Create a character array from one or more numeric matrices, character matrices or cell arrays. For numerical input, each element is converted to the corresponding ASCII character. The arguments (and elements of cell array(s)) are concatenated vertically. The returned values are padded with blanks as needed to make each row of the string array have the same length. Unlike char, empty strings are removed. For example,

          strvcat ([97, 98, 99], "", {"98", "99", 100}, ["num", "bers"])
               ⇒ ["abc    "
                  "98     "
                  "99     "
                  "d      "
                  "numbers"]
     
     
See also: char, strcat, cstrcat.

— Function File: strcat (s1, s2, ...)

Return a string containing all the arguments concatenated horizontally. If the arguments are cells strings, strcat returns a cell string with the individual cells concatenated. For numerical input, each element is converted to the corresponding ASCII character. Trailing white space is eliminated. For example,

          s = [ "ab"; "cde" ];
          strcat (s, s, s)
               ⇒ ans =
                  "ab ab ab "
                  "cdecdecde"
          s = { "ab"; "cde" };
          strcat (s, s, s)
               ⇒ ans =
                  {
                    [1,1] = ababab
                    [2,1] = cdecdecde
                  }
     
     
See also: cstrcat, char, strvcat.

— Function File: cstrcat (s1, s2, ...)

Return a string containing all the arguments concatenated horizontally. Trailing white space is preserved. For example,

          cstrcat ("ab   ", "cd")
               ⇒ "ab   cd"
          s = [ "ab"; "cde" ];
          cstrcat (s, s, s)
               ⇒ ans =
                  "ab ab ab "
                  "cdecdecde"
     
     
See also: strcat, char, strvcat.