- The column in the file is a cell
- most of value have 2dots
- some of value are arrays
- No Nan found
Numbers from a csv are not being read as doubles, but as chars?
9 views (last 30 days)
Show older comments
I am working on a project where I need to match runtimes to find specific rownumbers.
I'm running into an issue where for some participants I was forced to edit the original csv and after editing, the runtimes column is not being interpreted by matlab as a column of doubles anymore.
So if I load it in as a matrix, I get NaNs, and if I call the class of a cell it returns char. How do I get matlab to interpret these variables as doubles?
1 Comment
Mohammed Hamaidi
on 25 Mar 2022
Accepted Answer
Stephen23
on 25 Mar 2022
Edited: Stephen23
on 25 Mar 2022
"...I was forced to edit the original csv..."
That is the cause of your problem right there. Let me guess: you made the mistake of using Excel to edit the file?
"... and after editing the runtimes column is not being interpreted by matlab as a column of doubles anymore."
Because whatever tool you used (i.e. Excel) changed the CSV format. It might not even be a CSV file any more (e.g. semi-colon-separated with a misleading file extension).
MS Excel will happily open various text file formats (e.g. CSV) and then overwrite them with its own format. It can even change your data without warning (and once it has gone, there is no way to get it back again):
The solution is very simple: if you want reliable text file formats then do not use Excel to edit them.
If you uploaded the before and after files I could show you exactly how Excel changed your CSV fie format, but in lieu of that, here are some other threads where the OPs also suffered at the hands of Excel changing their file formats because they made the mistake to use Excel to edit some of their text files:
Do NOT use Excel to edit text files. Use a text file editor.
More Answers (0)
See Also
Categories
Find more on Data Import from MATLAB 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!