MATLAB: Read part of string

functionstring

I have mat file like 'name.mat'
name(1,1) = Italy
name(2,1) = Rome, Italy
And I want to get 'Rome'.
I do not know the function that I want.
Please help me.

Best Answer

This will work, but no guarantee that it will easily generalise to more complicated situations:
name(1,1) = {'Italy'};
name(2,1) = {'Rome, Italy'};
x = findstr(name{2},',');
y = name{2}(1:x-1)
produces:
y =
Rome
This is only one way (and probably the simplest). There are many others.
Related Question