필터 지우기
필터 지우기

How to extract table with only numerical values from table

조회 수: 55 (최근 30일)
Camilo Cárdenas
Camilo Cárdenas 2023년 7월 24일
편집: Cris LaPierre 2023년 7월 25일
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
Camilo Cárdenas
Camilo Cárdenas 2023년 7월 24일
Ups!... Thank you a lot!
herewith I close the question
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