我创建了一个文件,该文件生成一定数量的数据点,下面是简化版本。当我打开文本文件时,文本文件会将数字四舍五入,以降低精度。如何扩展文本文件中的有效位数?
%% Starting and ending location for signal
Ti = 0; %-1e-5
Step = .00000000004; %4e-11
Tend = .00005; %1e-5
%% Generates data
Total_data = (Tend-Ti)/Step;
V = zeros(1.25e6,2);
Velocity_Profile = zeros((1.25e6)+1,1);
Time_Profile = zeros((1.25e6)+1,1);
k = 1;
for i=Ti:Step:Tend
V(:,1) = i;
Velocity = 0;
if i<0
Velocity = 0;
end
if i>0
Velocity = 500;
end
Velocity_Profile(k,1) = Velocity_Profile(k,1) + Velocity;
Time_Profile(k,1) = Time_Profile(k,1) + i;
k = k+1;
end
Velocity_Profile;
Time_Profile;
Profile = [Time_Profile, Velocity_Profile];
fid=fopen(['Test.txt'],'w+');
fprintf(fid,'%f,%f\n',[Time_Profile,Velocity_Profile].');
fclose(fid);
查看fprintf功能的matlab文档。
为了提高精度,您可以输入
fprintf(fid,'%24.18f %24.18f\n',[Time_Profile,Velocity_Profile].');
例如打印精度为18位的数字。您也可以使用格式'%18.14e'打印14位精度,但使用指数格式(例如1.24e-2)。只要仔细阅读文档,您就可以找到最合适的文档。