How to extract table with only numerical values from table

36 次查看(过去 30 天)
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

采纳的回答

Voss
Voss 2023-7-24
Use () instead of {}
S = vartype('numeric');
tDatanum = tTest(:,S) % <- using () makes tDatanum another table
  2 个评论
Cris LaPierre
Cris LaPierre 2023-7-24
编辑:Cris LaPierre 2023-7-25
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)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by