How to change data type of table in matlab
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Iram Shahzadi
le 12 Nov 2018
Commenté : Iram Shahzadi
le 12 Nov 2018
I am reading a spreadsheet with 2 columns using readtable command in Matlab. Both columns of the table are read as a string. How two change the datatype of a second column to double.
2 commentaires
Stephen23
le 12 Nov 2018
"How two change the datatype of a second column to double."
Most likely if the data could be imported as numeric then it already would be... what kind of values are in those columns?
If you can, please upload the spreadsheet by clicking the paperclip button.
Réponse acceptée
Guillaume
le 12 Nov 2018
Really, you should change the way you store your data in the spreadsheet. As it is you're losing most of the benefit of the spreadsheet format. Even in excel, you wouldn't be able to use those numbers as they're stored as text.
One of the many ways of extracting the numbers from the text:
t = readtable('book1.xlsx');
t.patient = cellfun(@str2double, regexp(t.patient, '\d+', 'match'), 'UniformOutput', false)
If you didn't have those brackets [] around the text and the numbers had beens separated by spaces, it would have been easier.
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur Spreadsheets dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!