Extracting rows from table with specific digits

1 visualización (últimos 30 días)
Nadeau Hahne
Nadeau Hahne el 8 de Abr. de 2021
Respondida: Stephen23 el 8 de Abr. de 2021
Hello,
I have the following table below. I want pull the rows where the second digit is 2. So I am looking to pull all the rows that have the code '*2****.*' and making a new table from that.
x =
5×2 table
code description
____________ _________________
{'116004.5'} {'description 1'}
{'116006.6'} {'description 2'}
{'120099.9'} {'description 3'}
{'120199.3'} {'description 4'}
{'120202.5'} {'description 5'}

Respuesta aceptada

KSSV
KSSV el 8 de Abr. de 2021
code = [{'116004.5'}
{'116006.6'}
{'120099.9'}
{'120199.3'}
{'120202.5'}] ;
description = [ {'description 1'}
{'description 2'}
{'description 3'}
{'description 4'}
{'description 5'}] ;
T = table(code,description) ;
idx = contains(T.(2),'2') ;
T = T(idx,:)

Más respuestas (1)

Stephen23
Stephen23 el 8 de Abr. de 2021
I changed your example data so that the first code string contains '2' but not in the 2nd position, to make a more thorough test case.
code = {'116204.5';'116006.6';'120099.9';'120199.3';'120202.5'};
desc = {'description 1';'description 2';'description 3';'description 4';'description 5'};
T = table(code,desc)
T = 5×2 table
code desc ____________ _________________ {'116204.5'} {'description 1'} {'116006.6'} {'description 2'} {'120099.9'} {'description 3'} {'120199.3'} {'description 4'} {'120202.5'} {'description 5'}
X = cellfun(@isempty,regexp(T.code,'^.2'));
out = T(~X,:)
out = 3×2 table
code desc ____________ _________________ {'120099.9'} {'description 3'} {'120199.3'} {'description 4'} {'120202.5'} {'description 5'}

Categorías

Más información sobre Cell Arrays 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