MATLAB: I have a character vector with repeated elements and want to extract each element once and at the sequence of appearance.

character vector

Hi all,
I have a character vector with repeated elements and want to extract each element once, at the sequence of appearance in the original file. I am attaching an example file. In fact, I need to get:
Group Frontal_L Ins_Cing_L etc..
I guess I will have to use regexp but not very experienced with this functionality. Any ideas very welcome.

Best Answer

[unames,ia,iu]=unique(strtrim(cellstr(Getcurvenames)),'stable');
unames will be the names that are unique in the overall list,
unames=Getcurvenames(ia); % ia is location vector in original list Getcurvenames
Getcurvenames=unames(iu); % rebuild the original from the indices in unique list
unames will be cellstr list of names, much more conveniently handled than are fixed-length char arrays.
ADDENDUM
I forgot about the request for initial order in the output; use the 'stable' option as shown above. To not return the group string, make a slight modification to eliminate it first --
cnames=strtrim(cellstr(Getcurvenames)); % convert to trimmed cellstr
cnames=cnames(~contains(cnames,'Group')); % keep only those ~='Group'
[unames,ia,iu]=unique(cnames)),'stable'); % and the unique list of those
Related Question