Convert excel file data from char to number or double
4 views (last 30 days)
Show older comments
I have an excel file that contains disease data in char format. I have tried severally to convert from char to number or double.
RecentData = char2double(RecentData); But its not working
4 Comments
Answers (2)
Walter Roberson
on 29 Mar 2019
T = readtable('Recent data.xlsx');
Then T.AGE will be numeric, and that can also be accessed as T{:,2} .
None of your other fields are numeric, except that you have an empty field just before Result and you could call that emptiness NaN I suppose.
Your other entries are all character vectors. Depending what you want to do with them, you might want to consider using categorical() on them; in most contexts categorical variables can be used as labels. You could also consider things like,
findgroups(T.GeneralMalaise)
which will return a numeric result with group numbers, suitable for routines that need a numeric group label.
My testing suggests that using
temp = categorical(T.GeneralMalaise);
double(temp) %returns numeric code
returns the same numbers as would be returned by
findgroups(T.GeneralMalaise)
0 Comments
See Also
Categories
Find more on Spreadsheets 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!