How to use regexp to extract data?

3 visualizaciones (últimos 30 días)
Pete sherer
Pete sherer el 23 de Sept. de 2020
Respondida: Stephen23 el 23 de Sept. de 2020
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

Respuesta aceptada

Stephen23
Stephen23 el 23 de Sept. de 2020
>> 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'

Más respuestas (0)

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by