Borrar filtros
Borrar filtros

how to export numerical part without decimal and digit with fractional part in the same array

2 visualizaciones (últimos 30 días)
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 comentario
Jan
Jan el 11 de Dic. de 2017
"dlmwrite with precision" does not reveal the detail, what you used to specify the precision. What about '%16g'?

Iniciar sesión para comentar.

Respuesta aceptada

KL
KL el 11 de Dic. de 2017
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 comentario
Jan
Jan el 11 de Dic. de 2017
+1. If the general method of defining the precision in dlmwrite is too coarse, use fprintf, which allows to control the output individually.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by