Saving imported date to a new file
Show older comments
Hi, Im trying to import date from a .dat file. I can import it and see it in matlab, I changed one of the colums and then saved it to a new .dat file. Only now it saves them in a short form, only up to 7 places after the decimal, and I need way more. Making it useless. I used this code.
format long;
Mag = -2.5*log10(VarName2);
data_out = [VarName1, Mag, VarName3, VarName4, VarName5];
save my_data.dat data_out -ASCII
After I imported all the data, and the import did work.
Answers (1)
Jan
on 4 May 2017
0 votes
Storing numbers in ASCII files is only useful, if you want to edit the files manually. Prefer binary files, because they are smaller and much faster to read. Then you store the values with the full precision, while even fprintf('%.16g') rounds in the last digit.
Using save for ascii files is a weak method. You have limited control over the precision and a poor performance. Better store the files in binary format or prefer fopen and fprintf.
Categories
Find more on Low-Level File I/O 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!