How to convert a table data to numeric data without loosing data
23 次查看(过去 30 天)
显示 更早的评论
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/931274/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/931279/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/931284/image.jpeg)
1 个评论
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
2022-3-18
data = table([1;2], [3;4], [5;6], ["Healthy";"Disease"], 'variablenames', {'Energy', 'variance', 'std', 'class'})
[data.class, groups] = findgroups(data.class)
table2array(data)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!