Why are csvwrite and writetable producing different sized files?
1 view (last 30 days)
Show older comments
MathWorks Support Team
on 3 Aug 2016
Answered: MathWorks Support Team
on 22 Aug 2016
I have 200 tables in individual *.mat files with one table each (table values stored as double precision). I need to convert them to CSV to be read-in to R and tried out the two different methods:
1) writetable(, 'WriteVariableNames', false))
2) csvwrite(table2array())
The writetable output produces file sizes 25-90% larger than the similar csvwrite(table2array). Can you explain this behavior and why I should choose one method over the other?
The tables are approximately 4000x3500 in size so if there is significant differences between the two, I'd like to be aware of the differences in behavior.
Accepted Answer
MathWorks Support Team
on 3 Aug 2016
The discrepancy in file sizes appears to be the result of intended behavior of the "csvwrite" function. "csvwrite" only writes the first five significant digits of its matrix argument to file. "writetable" does not have this limitation. The result is that "csvwrite" produces files with significantly fewer characters in them than files produced by "writetable", and thus the files are significantly smaller.
For more information about the "csvwrite" function, you can follow the link below to our documentation:
http://www.mathworks.com/help/matlab/ref/csvwrite.html?searchHighlight=significant%20digits
0 Comments
More Answers (0)
See Also
Categories
Find more on Text Data Preparation 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!