Printing just one column in text file in scientific notation

2 次查看(过去 30 天)
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!

采纳的回答

dpb
dpb 2018-12-2
>> 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 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by