Using readtable() for Excel file where only one column has mixed numbers and text
20 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Douglas Anderson
le 7 Avr 2022
Modifié(e) : Stephen23
le 7 Avr 2022
Hello,
When using readtable() for an Excel file, there are thirteen columns, some of which are only text and most of them only numbers. The first column, and identifier, sometimes is integers and sometimes text. If it starts out integers, the text ones become NaN.
Is there a way to read only one column as text even if it starts out as number? I'd rather not read it ALL in as text and then convert the rest one-by-one. Looked through the readtable() documentation and didn't see this.
Thanks.
Doug Anderson
0 commentaires
Réponse acceptée
Stephen23
le 7 Avr 2022
Modifié(e) : Stephen23
le 7 Avr 2022
Of course you can specify the class, the simplest approach is probably via DETECTIMPORTOPTIONS and SETVARTYPE:
fnm = 'filename.xlsx';
opts = detectImportOptions(fnm);
opts = setvartype(opts,1,'string');
tbl = readtable(fnm,opts)
0 commentaires
Plus de réponses (0)
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!