Saving imported date to a new file

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
Jan on 4 May 2017
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.

1 Comment

I now used dlmwrite, and it seems to work better. But im still missing about 2 digits. I used importdata to import it, maybe its not importing everything? The numbers are about 20 digits long + scientific notation. Everything works, but now it still only rounds up to about 17-18 digits, and idk why.
Should I use other commands?

Sign in to comment.

Asked:

on 4 May 2017

Commented:

on 4 May 2017

Community Treasure Hunt

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

Start Hunting!