Printing just one column in text file in scientific notation

2 views (last 30 days)
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!

Accepted Answer

dpb
dpb on 2 Dec 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...

More Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!