How to extract table with only numerical values from table
49 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Voss
on 24 Jul 2023
Use () instead of {}
S = vartype('numeric');
tDatanum = tTest(:,S) % <- using () makes tDatanum another table
2 Comments
Cris LaPierre
on 24 Jul 2023
Edited: Cris LaPierre
on 25 Jul 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)
More Answers (0)
See Also
Categories
Find more on Data Preprocessing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!