How to split a column in a table into two columns?

Hi,
I have a table that has column like this:
name_num
ABC_123
EFG_456
GGGG
HHHHH
I would like to split the column into two: name and num like this:
name num
ABC 123
EFG 456
GGGG N/A
HHHHH N/A
I thought of varfun but I have difficulty with it. Would anyone help me?
Thank you.
Jennifer

 Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 24 de Ag. de 2015
Editada: Azzi Abdelmalek el 24 de Ag. de 2015
name_num={'ABC_123','EFG_456','GGGG','HHHHH'}
s1=regexp(name_num,'[^\d_]+','match')
s2=regexp(name_num,'\d+','match')
s2(cellfun(@isempty,s2))={'N/A'}
out=[[s1{:}]' [s2{:}]']

1 comentario

JFz
JFz el 25 de Ag. de 2015
Azzi, Thank you! yes, it works! But in my case, it is a table. So should I convert name_num column into a cell array and perform the regexp before convert back to table?
Jennifer

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Type Conversion en Centro de ayuda y File Exchange.

Productos

Etiquetas

Aún no se han introducido etiquetas.

Preguntada:

JFz
el 24 de Ag. de 2015

Comentada:

JFz
el 25 de Ag. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by