Readtable() Skipps last rows of csv
6 views (last 30 days)
Show older comments
Tim Rothhaupt
on 1 Jul 2022
Commented: Star Strider
on 4 Jul 2022
Hello there,
I have some issues with importing and exporting data.
I am summerizing some measurment data in one script which then saves the summarized data in a csv file for easy sharing (using writetable(table, filename).
Now I would like to import this data to work with it again and therefore I try to import it using readtable(filename).
The issue ist, that I export a 392x10 table and it only imports a 323x10 table. It just skipps the last 70 rows somehow.
When I open the csv-file in excel I can see that the export worked fine.
%Script 1
...
filename = 'measurementdata.csv';
writetable(table,filename);
Import said file in different script
%Script 2
table2 = readtable('measurementdata.csv');
%Access colums by name
temps = unique(table2.targTemp);
volts = unique(table2.targVlt);
curr = unique(table2.targCurr);
...
I have attached the measurmentdata.csv file
0 Comments
Accepted Answer
Star Strider
on 1 Jul 2022
Edited: Star Strider
on 1 Jul 2022
If you are using the unique function before writing the output file, it could be deleting several entries. Also, the correct approach is likely to be:
table2u = unique(table2, 'rows');
to avoid scrambling the individual columns (variables).
I have not checked by looking at it in Excel, however it appears to be read correctly (as a (392x8) table) in R2022a —
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1052370/measurementdata.csv', 'VariableNamingRule','preserve')
LastRow = T1(392,:)
Check to be sure all the updates to R2017b are downloaded and installed, since there could be a bug that was subsequently fixed. (I no longer have R2017b installed here, so I cannot test it.)
.
4 Comments
More Answers (0)
See Also
Categories
Find more on Matrices and Arrays 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!