Q:

How to extract certain words from character vector in MATLAB?

How to extract certain words from a character vector in MATLAB?
I am struggling to work that out. I would like to obtain only the city names from this character vector: 
myText = 'Vienna 2.7  Gallen  3.8  Zurich 0.9    Lugano 2.8   Rome 12.1   Paris 9.2'

A:

You can break the string into a vector of strings using this:
cities = split(myText);

Then index just the names:
cities = cities(1:2:end);

A:

This handles several-word names (San Francisco, Newcastle upon Tyne), including dashes (Carmel-by-the-Sea), apostrophes (L'Aquila) or dots followd by a space (St. Gallen). It assumes that the names are separated by any character other than letters, dash, space or apostrophe, and that the numbers never end in a dot:
result = strtrim(regexp(myText, '([a-zA-Z\- '']|\. )+', 'match'));

Example:
>> myText = 'San Francisco 2.7  Newcastle upon Tyne  3.8  Carmel-by-the-sea 0.9    L''Aquila 2.8  St. Gallen';
>> result = strtrim(regexp(myText, '([a-zA-Z\- '']|\. )+', 'match'))  
result =
  1×5 cell array
    {'San Francisco'}    {'Newcastle upon Tyne'}    {'Carmel-by-the-sea'}    {'L'Aquila'}    {'St. Gallen'}

