readtable behaves different after editing CSV?
Afficher commentaires plus anciens
I have one CSV file output from some software. The original CSV file (one attached without 'edited' appended) has some header lines which I don't care about and a column of times which I do care about.
The column of times in the original file is incorrect since some stuff happened during the acquisition. I have edited the said CSV file to fix the errors. When I use the code below on the edited file I get the error at the final line saying Input data must be a real, numeric array. If I run the same code on the unedited CSV file it runs fine and behaves as expected; outputting a vector of the original times in seconds, which is what I want. I'm really unsure why this is happening - I've not changed anything else in the CSV files aside from adding a few times, but the number format of all the cells afaik is the same in both CSV files.
ons_csv = readtable('S17.csv');
ons_times = ons_csv(:,1);
ons_times = table2array(ons_times);
ons_seconds = seconds(ons_times);
1 commentaire
"I've not changed anything else in the CSV files aside from adding a few times, but the number format of all the cells afaik is the same in both CSV files."
No, it isn't. The problem is that you used Excel to alter a CSV text file. Every time you open and then save a CSV file with Excel, it will completely re-write the file using what Excel thinks is a CSV format. There is nothing preventing Excel from changing the file format or data formats, e.g. delimiters, dates, string quotations, numbers, etc. Even if you think you only changed some small part of the CSV file, Excel makes zero effort to keep the "rest" of the file unchanged.
We learn two lessons from this:
- If you want to compare CSV files then use a reputable file comparison tool (MATLAB has one inbuilt).
- Do not use Excel if a particular file format and/or data needs to be preserved.
CSV files are just text: if you only need to make a few changes then you should use a reputable text editor:
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Spreadsheets dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!