limit the -ascii output to two decimal points
9 views (last 30 days)
Show older comments
save(fullfile(PathName,filename),'x','-ascii');
how to save the files upto two decimals
0 Comments
Answers (1)
Walter Roberson
on 26 Feb 2023
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 Comments
Walter Roberson
on 26 Feb 2023
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?
See Also
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!