how to export numerical part without decimal and digit with fractional part in the same array
1 次查看(过去 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!