Readtable() Skipps last rows of csv

9 vues (au cours des 30 derniers jours)
Tim Rothhaupt
Tim Rothhaupt le 1 Juil 2022
Commenté : Star Strider le 4 Juil 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

Réponse acceptée

Star Strider
Star Strider le 1 Juil 2022
Modifié(e) : Star Strider le 1 Juil 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')
T1 = 392×8 table
targVlt targCurr targTemp maxTrq minTrq avgTrq maxCurr minCurr _______ ________ ________ _______ ________ _______ _______ _______ 9 2500 23 0.78394 -0.44696 0.65847 15.637 -1.5509 9 2500 23 0.76172 -1.3036 0.64853 18.255 -1.7725 9 3500 23 1.0045 -0.51398 0.88617 35.812 -3.2562 9 3500 23 0.97003 -1.2741 0.86851 44.714 -18.51 9 4500 23 1.2412 -0.50653 1.0606 50.388 -12.857 9 4500 23 1.1934 -1.181 1.0497 43.586 -9.7418 9 5500 23 1.2456 -0.52069 1.1492 56.457 -17.087 9 5500 23 1.2357 -1.2138 1.0815 43.842 -16.798 11 2500 23 0.74036 -0.5166 0.66467 11.111 -1.3696 11 2500 23 0.80347 -1.1976 0.65165 15.402 -4.4647 11 3500 23 0.95367 -0.52124 0.86345 22.256 -7.0294 11 3500 23 0.99969 -1.3061 0.85621 27.836 -6.6467 11 4500 23 1.1523 -0.52136 1.0639 38.376 -17.577 11 4500 23 1.1912 -1.285 1.0513 42.982 -19.054 11 5500 23 1.3141 -0.53064 1.1485 52.1 -1.6852 11 5500 23 1.2513 -1.252 1.1352 46.373 -4.6527
LastRow = T1(392,:)
LastRow = 1×8 table
targVlt targCurr targTemp maxTrq minTrq avgTrq maxCurr minCurr _______ ________ ________ _______ _______ _______ _______ _______ 15.5 2500 120 0.62531 -1.7099 0.53204 21.035 -2.605
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 commentaires
Tim Rothhaupt
Tim Rothhaupt le 4 Juil 2022
Thanks for the answer.
That was my bad. The newest table is only 8 columns, but still it is the correct file.
I've checked for Matlab Updates and now it seems to be working. Must have been a bug somehow.
Star Strider
Star Strider le 4 Juil 2022
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Produits


Version

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by