How to use regexp to extract data?

1 回表示 (過去 30 日間)
Pete sherer
Pete sherer 2020 年 9 月 23 日
回答済み: Stephen23 2020 年 9 月 23 日
Hi I have this cell array, and want to extract character before and after the "__"
tdata = {'XX__TG','GB_TH','BN__TH'}';
I want to use regexp and return me
out1 = {'XX'; 'GB'; 'BN'};
out2 = {'TG'; 'TH'; 'TH'};
Thanks

採用された回答

Stephen23
Stephen23 2020 年 9 月 23 日
>> tdata = {'XX__TG';'GB_TH';'BN__TH'};
>> spl = regexp(tdata,'_+','split');
>> spl = vertcat(spl{:});
>> out1 = spl(:,1)
out1 =
'XX'
'GB'
'BN'
>> out2 = spl(:,2)
out2 =
'TG'
'TH'
'TH'

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by