I think the answer to both (1) and (2) is .mat file. ASCII files (like CSV) require conversion to and from the format in memory (binary), which makes them slow. Moreover, if written at more than 6 significant figures, they are bigger than the usual (double precision) binary format as well. Therefore, you should probably only use CSV if either (a) you need to exchange data with software that can read CSV but cannot read MAT (like Excel) or (b) you want to be able to peruse the data yourself in a text editor or CSV editor.
Aside, if speed is your absolute goal, consider using
save myvariable myfile -v6
because both the save() and load() commands are much quicker if compression is disabled like this (compression was not available in Version 6 of Matlab). Vice versa, if small file size is your goal, use the usual save/load commands.
Depending on the data, you might get some additional savings by first casting to a smaller data type. For instance, if you are storing data as double precision but are confident that single precision will be enough... try this:
a = randn(1000, 1);
save a1 a
a = single(a);
save a2 a
and check the filesizes. Note that the filesize has got smaller in a2 because you've thrown away information which you judged yourself to be irrelevant.
4 Comments
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/8261-csv-vs-mat-files#comment_17793
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/8261-csv-vs-mat-files#comment_17793
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/8261-csv-vs-mat-files#comment_17801
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/8261-csv-vs-mat-files#comment_17801
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/8261-csv-vs-mat-files#comment_17814
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/8261-csv-vs-mat-files#comment_17814
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/8261-csv-vs-mat-files#comment_17823
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/8261-csv-vs-mat-files#comment_17823
Sign in to comment.