limit the -ascii output to two decimal points
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
save(fullfile(PathName,filename),'x','-ascii');
how to save the files upto two decimals
0 Kommentare
Antworten (1)
Walter Roberson
am 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 Kommentare
Walter Roberson
am 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?
Siehe auch
Kategorien
Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!