Effacer les filtres
Effacer les filtres

Printing just one column in text file in scientific notation

2 vues (au cours des 30 derniers jours)
g
g le 2 Déc 2018
Réponse apportée : dpb le 2 Déc 2018
I am creating a text file with two columns of data using the following scheme:
data = [a b]
datafile = sprintf('file_%s.txt',label);
fileID = fopen(datafile,'w');
fprintf(fileID,'%f %f\n',data');
fclose(fileID);
I want the first column to be just the regular numbers, but the second column has very small values, so I want those printed out in the text file in scientific notation. How would I apply scientific notation to just that column? So when I open the text file it looks something like this (numbers arbitrary):
110.51 1.2222e-13
111.50 1.3897e-13
112.49 1.2342e-14
113.48 8.8123e-15
Thanks!

Réponse acceptée

dpb
dpb le 2 Déc 2018
>> ab=[110.51 1.2222e-13
111.50 1.3897e-13
112.49 1.2342e-14
113.48 8.8123e-15];
>> fmt=['%8.2f %12.5e \n'];
>> fprintf(fmt,ab.')
110.51 1.22220e-13
111.50 1.38970e-13
112.49 1.23420e-14
113.48 8.81230e-15
>>
Salt to suit...

Plus de réponses (0)

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by