How to print an array with same column starting locations?
Afficher commentaires plus anciens
I have an array with varying size data values:
A = [ 1.1 2.123 3.12
1 45.1234 567
1.23 -3.1 7.34567]
I would like to print the array to a file so that it displays with a flush column starting location as shown. I don't mind going line by line through a for loop, but the size of the array is open to variance, so I cannot go manually line by line.
I have tried using %f designation within fprintf, but this fixes the location of the decimal rather than the first character. I have also tried %e and %g as I don't mind having extra zeroes at the end, however, these two do not properly account for the negative value as shown below.
for I = 1:3
fprintf(file,'%1.6e %1.6e %1.6e\n',A(I,:));
end
1.100000e+00 2.123000e+00 3.120000e+00
1.000000e+00 4.512340e+01 5.670000e+02
1.230000e+00 -3.100000e+00 7.345670e+00
Is there some command other than fprintf which can perform this output, or is there some setting within fprintf which can produce the consistent column locations I would like?
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Matrices and Arrays dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!