Borrar filtros
Borrar filtros

How to extract table with only numerical values from table

55 visualizaciones (últimos 30 días)
Hallo all,
I have a table with diferent types of data (timestamp, strings, number); for example:
tTest =
9×5 table
Time ms M_1.20 M_38.00 MeasID
____________________ _____ __________ __________ _______
21-Jul-2023 12:50:13 620 2.8353e-10 7.5855e-10 "bc08_"
21-Jul-2023 12:50:16 3098 2.6337e-10 7.4578e-10 "bc08_"
21-Jul-2023 12:50:17 4121 2.5599e-10 7.4713e-10 "bc08_"
21-Jul-2023 12:50:18 5159 2.6741e-10 7.525e-10 "bc08_"
21-Jul-2023 12:50:19 6181 2.6807e-10 7.5653e-10 "bc08_"
21-Jul-2023 12:50:20 7206 2.7346e-10 7.5317e-10 "bc08_"
21-Jul-2023 12:50:21 8239 2.721e-10 7.4645e-10 "bc08_"
21-Jul-2023 12:50:22 9250 2.4859e-10 7.6594e-10 "bc08_"
21-Jul-2023 12:50:23 10256 2.4725e-10 7.5854e-10 "bc08_"
and I would like to extract another table but with only the numerical values; it is the columns 2 to 4.
If I use "vartype":
>> S = vartype('numeric');
tDatanum = tTest{:,S}
tDatanum =
1.0e+04 *
0.0620 0.0000 0.0000
0.3098 0.0000 0.0000
0.4121 0.0000 0.0000
0.5159 0.0000 0.0000
0.6181 0.0000 0.0000
0.7206 0.0000 0.0000
0.8239 0.0000 0.0000
0.9250 0.0000 0.0000
1.0256 0.0000 0.0000
I get the numerical information, but I lost the name of the variables.
In Advance, many thanks, Camilo

Respuesta aceptada

Voss
Voss el 24 de Jul. de 2023
Use () instead of {}
S = vartype('numeric');
tDatanum = tTest(:,S) % <- using () makes tDatanum another table
  2 comentarios
Camilo Cárdenas
Camilo Cárdenas el 24 de Jul. de 2023
Ups!... Thank you a lot!
herewith I close the question
Cris LaPierre
Cris LaPierre el 24 de Jul. de 2023
Editada: Cris LaPierre el 25 de Jul. de 2023
You must keep your data in a table if you want to preserve the variable names. Indexing with {} returns an array while indexing with () returns a table. See this page: https://www.mathworks.com/help/matlab/matlab_prog/access-data-in-a-table.html
The syntax you want is probably this
S = vartype('numeric');
tDatanum = tTest(:,S)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by