how do I save a double array in matlab to file as full precision double numbers?

조회 수: 33 (최근 30일)
mahaju
mahaju 2013년 9월 10일
댓글: Mohamad Mossad 2020년 2월 9일
I have an array of double variables which I save into a file using the command
save windparam.dat awindow -ascii
The array contains these values (using format long):
0.005000000000000
0.005008727005636
0.005034902724414
0.005078511265159
0.005139526153297
However, they are saved in the file as shown below:
5.0000000e-003
5.0087270e-003
5.0349027e-003
5.0785113e-003
5.1395262e-003
How can I get to save in the file in the same format as is shown in Matlab?

답변 (2개)

Walter Roberson
Walter Roberson 2013년 9월 10일
save windparam.dat awindow -ascii -double

Azzi Abdelmalek
Azzi Abdelmalek 2013년 9월 10일
편집: Azzi Abdelmalek 2013년 9월 10일
a=[0.005000000000000
0.005008727005636
0.005034902724414
0.005078511265159
0.005139526153297]
b=sprintf('%.15f\n',a)
If you want to save in a text file
fid=fopen('file1.txt','w');
b=fprintf(fid,'%.15f\n',a)
fclose(fid)
  댓글 수: 1
Jan
Jan 2013년 9월 10일
편집: Jan 2013년 9월 10일
+1, While the -double flag solves the problem for the save command, I'd prefer this approach based on fprintf, because it offers full control of the format.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Workspace Variables and MAT-Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by