how to get the first 3 characters of each element in a cell to another cell
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
0 comentarios
Respuesta aceptada
Jan
el 17 de Mzo. de 2014
filename = {'CD2.2008052716-17hZCFPF.GY.txt', ...
'GOM.2008052716-17hZCFPF.GY.txt', ...
'GYA.2008052716-17hZCFPF.GY.txt'};
P = strtok(filename, '.')
Más respuestas (2)
Azzi Abdelmalek
el 17 de Mzo. de 2014
out=cellfun(@(x) x{1},regexp(filename,'[^\.]+(?=\.(.+))','match'),'un',0)
1 comentario
Jan
el 17 de Mzo. de 2014
Or without cellfun:
regexp(filename,'[^\.]+(?=\.(.+))', 'match', 'once')
Andrei Bobrov
el 17 de Mzo. de 2014
In the general case:
filename = {'CZXDD2.2008052716-17hZCFPF.GY.txt', 'GOM.2008052716-17hZCFPF.GY.txt','GY3SAA9.2008052716-17hZCFPF.GY.txt'};
out = regexp(filename,'^\w*(?=\.)','match');
out = [out{:}];
0 comentarios
Ver también
Categorías
Más información sobre Cell Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!