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
Jan 2017 年 12 月 11 日
"dlmwrite with precision" does not reveal the detail, what you used to specify the precision. What about '%16g'?

サインインしてコメントする。

採用された回答

KL
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
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 ExchangeText Files についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by