how to export numerical part without decimal and digit with fractional part in the same array
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello, I have a foll. array, which I want to export in a text document:
1.000 1.000 6338110.000 0.198 0.064 1.701 1.505 0.035 0.043 0.160
1.000 1.000 6338130.000 0.211 0.048 1.885 1.769 0.026 0.041 0.506
1.000 1.000 6340210.000 0.309 0.004 3.054 4.318 0.028 0.045 0.420
1.000 1.000 6340216.000 0.289 0.007 2.876 3.997 0.018 0.046 0.912
B =
1 1 6338110 0.198 0.064 1.701 1.505 0.035 0.043 0.160
1 1 6338130 0.211 0.048 1.885 1.769 0.026 0.041 0.506
1 1 6340210 0.309 0.004 3.054 4.318 0.028 0.045 0.420
1 1 6340216 0.289 0.007 2.876 3.997 0.018 0.046 0.912
If I use dlmwrite with precision, it always shows all 3 digits together, & if In use dlmwrite without precision all station IDs in column 3 is rounded to a scientific digit (e.g., 6.33e+4) form. Can anybody help me how to export it as in Matrix B format? Thanks,
댓글 수: 1
Jan
2017년 12월 11일
"dlmwrite with precision" does not reveal the detail, what you used to specify the precision. What about '%16g'?
채택된 답변
KL
2017년 12월 11일
One approach is to use fprintf and then specify the output format,
A = [1.000 1.000 6338110.000 0.198 0.064 1.701 1.505 0.035 0.043 0.160
1.000 1.000 6338130.000 0.211 0.048 1.885 1.769 0.026 0.041 0.506
1.000 1.000 6340210.000 0.309 0.004 3.054 4.318 0.028 0.045 0.420
1.000 1.000 6340216.000 0.289 0.007 2.876 3.997 0.018 0.046 0.912];
fid = fopen('hithere.txt','w');
fspec = '%d,%d,%d,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f\n'; %here you mention the format you want
fprintf(fid,fspec,A.');
fclose(fid);
댓글 수: 1
Jan
2017년 12월 11일
+1. If the general method of defining the precision in dlmwrite is too coarse, use fprintf, which allows to control the output individually.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Text Files에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!