MATLAB: How to get the first 3 characters of each element in a cell to another cell

cell

filename={'CD2.2008052716-17hZCFPF.GY.txt', 'GOM.2008052716-17hZCFPF.GY.txt','GYA.2008052716-17hZCFPF.GY.txt'}
then I want to get a new cell
it would be like {'CD2',"GOM','GYA'};
how to make it

Best Answer

filename = {'CD2.2008052716-17hZCFPF.GY.txt', ...
'GOM.2008052716-17hZCFPF.GY.txt', ...
'GYA.2008052716-17hZCFPF.GY.txt'};
P = strtok(filename, '.')