Printing just one column in text file in scientific notation
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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!
0 Commenti
Risposta accettata
dpb
il 2 Dic 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...
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Get Started with MATLAB in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!