Skip to main content

7.2) Forming Strings: Concatenation


Sometimes we may want to construct strings from smaller strings. For example, we may want Matlab to plot a graph and have Matlab form a plot title by concatenating a strings with the data file name. Alternatively we may want to save a file with a file name that Matlab will derive according to some logical statement. How can we do this?

  • Strings can be joined just like numerical vectors
  • [matlab]
    >> firstname='Elvis'; secondname='Presley';
    >> fullname=[firstname, ' ', secondname];
    [/matlab]

  • Alternatively the function strcat concatenates strings horizontally
  • [matlab]
    >> fullname=strcat(firstname, secondname);
    [/matlab]