Skip to main content

7.1) Strings


A "string" is a sequence of characters enclosed within single quotes. It is a row vector of characters (of class char).

  • Strings can be combined into normal multi-dimensional arrays, but the rows must have the same number of characters as each other, and the columns likewise. This can be achieved by padding shorter strings with the space character.
  • However, because words are more meaningful units than individual letters, strings are generally best stored within cell arrays. The elements of these can be strings of different lengths.
  • We can use strings to store file names, or to specify annotations on plots (axis labels, titles, etc). We can also generate strings to execute outside of Matlab or as data entries within a database.

Strings are created using single quotes:

[matlab]
>> string1='School of Earth and Environment';
>> string2=['University ' 'of' ' Leeds'];
>> address=[string1, ', ', strings2]
address=School of Earth and Environment, University of Leeds
[/matlab]

Strings can be displayed using the "display" command:

[matlab]
>> display(address)
>> display('School of Earth and Environment, University of Leeds')
[/matlab]