How to use regexp to extract data?

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Logical 的更多信息

标签

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by