how to get the first 3 characters of each element in a cell to another cell

2 ビュー (過去 30 日間)
Roger
Roger 2014 年 3 月 17 日
コメント済み: Roger 2014 年 3 月 18 日
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

採用された回答

Jan
Jan 2014 年 3 月 17 日
filename = {'CD2.2008052716-17hZCFPF.GY.txt', ...
'GOM.2008052716-17hZCFPF.GY.txt', ...
'GYA.2008052716-17hZCFPF.GY.txt'};
P = strtok(filename, '.')

その他の回答 (2 件)

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 3 月 17 日
out=cellfun(@(x) x{1},regexp(filename,'[^\.]+(?=\.(.+))','match'),'un',0)
  1 件のコメント
Jan
Jan 2014 年 3 月 17 日
Or without cellfun:
regexp(filename,'[^\.]+(?=\.(.+))', 'match', 'once')

サインインしてコメントする。


Andrei Bobrov
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{:}];

カテゴリ

Help Center および File ExchangeCell Arrays についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by