limit the -ascii output to two decimal points
5 次查看(过去 30 天)
显示 更早的评论
save(fullfile(PathName,filename),'x','-ascii');
how to save the files upto two decimals
0 个评论
回答(1 个)
Walter Roberson
2023-2-26
You cannot do that -- the -ascii flag always outputs a number of digits . However you can
format long g
PathName = '.'; filename = 'test.txt';
x = rand(1,11).' .* 10.^(-5:5).'
%if you mean two digits after the decimal place
dlmwrite(fullfile(PathName, filename), x, 'precision', '%.2f')
dbtype(fullfile(PathName, filename))
%if you mean two significant digits
temp = round(x, 2, 'significant');
dlmwrite(fullfile(PathName, filename), temp)
dbtype(fullfile(PathName, filename))
3 个评论
Walter Roberson
2023-2-26
The above example shows that using dlmwrite with 'precision' does work.. well, except possibly not for infinite or nan values, or for non-numeric values.
What output are you observing when you try?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!