how to get the first 3 characters of each element in a cell to another 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
채택된 답변
추가 답변 (2개)
Azzi Abdelmalek
2014년 3월 17일
out=cellfun(@(x) x{1},regexp(filename,'[^\.]+(?=\.(.+))','match'),'un',0)
댓글 수: 1
Jan
2014년 3월 17일
Or without cellfun:
regexp(filename,'[^\.]+(?=\.(.+))', 'match', 'once')
Andrei Bobrov
2014년 3월 17일
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{:}];
카테고리
도움말 센터 및 File Exchange에서 Cell Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!