フィルターのクリア

Printing just one column in text file in scientific notation

2 ビュー (過去 30 日間)
g
g 2018 年 12 月 2 日
回答済み: dpb 2018 年 12 月 2 日
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 Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by