Import a spreadsheet with columns containing both string and numeric values using readtable()
63 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jack Parsons
el 19 de Feb. de 2021
Comentada: Jack Parsons
el 23 de Feb. de 2021
I have a spreadsheet I am trying to import with readtable(). Mostly, the import works perfectly. However, there is a single column of data that has both numeric values and strings in it. Matlab reads the numeric values but recodes the strings as 'NaN'.
So for example, in the Excel spreadsheet I have a column "Response = {5, 10, cat, 12}". However, Matlab reads this as "Response = [5 10 NaN 12]".
I would like Matlab to read it as a cell array with the values as they are in the .xlsx spreadsheet.
I suspect this is possible with spreadsheetImportOptions, but I'm not sure how.
Thanks!
file = 'rating_task_raw_21_02_17.xlsx';
Data.Task_Raw = readtable(file);
0 comentarios
Respuesta aceptada
Cris LaPierre
el 19 de Feb. de 2021
In this instance, MATLAB has selected a numeric data type for the column. You can use the optoins to change the data type used to meet your needs. In this instance, I would probably use categorical, but char or string should work, too.
Más respuestas (0)
Ver también
Categorías
Más información sobre Spreadsheets en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!