How to convert a table data to numeric data without loosing data

조회 수: 46 (최근 30일)
C PRASAD
C PRASAD 2022년 3월 18일
답변: Walter Roberson 2022년 3월 18일
I have a tabel data and I would like convert it to numeric data. I have used table2aray then I get the into String.But I want it as a Numeric data and Then I used str2double and I got the double type data where I lost the sata of 6 column.Now I want to conert my table data into Numeric and No information could not be lost.Please help me with this using MATALAB
  댓글 수: 1
Arif Hoq
Arif Hoq 2022년 3월 18일
data of column 6 is string, so if you want to convert into numeric it will return 'NaN'. you have to work with this column 6 as a cell array of character vector or a string array.
what is you expectation except this ?

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2022년 3월 18일
data = table([1;2], [3;4], [5;6], ["Healthy";"Disease"], 'variablenames', {'Energy', 'variance', 'std', 'class'})
data = 2×4 table
Energy variance std class ______ ________ ___ _________ 1 3 5 "Healthy" 2 4 6 "Disease"
[data.class, groups] = findgroups(data.class)
data = 2×4 table
Energy variance std class ______ ________ ___ _____ 1 3 5 2 2 4 6 1
groups = 2×1 string array
"Disease" "Healthy"
table2array(data)
ans = 2×4
1 3 5 2 2 4 6 1
That is, the class data has been grouped into categories, and for each entry a category number was generated and replaces the strings in the table. Now the class column is a code that indicates the class, but has no inherent numeric meaning. You can take the value of the column and use it to index the groups variable to recover the class string information.

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by