Issue with saving text file using sprintf
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Turbulence Analysis
am 6 Mai 2024
Bearbeitet: Dyuman Joshi
am 6 Mai 2024
Hi,
I am using the below commad to write data file to text file.
Ideally I want my text file to saved as as 'data_0.5.txt', unfortunately now it is saved as 'data_0.500000.txt'. Essentialy I want to limit to one digits after the decimal point.
h=0.5
writetable(data,sprintf('data_%f.txt',w));
1 Kommentar
Dyuman Joshi
am 6 Mai 2024
Bearbeitet: Dyuman Joshi
am 6 Mai 2024
I'll repeat my comment here - https://in.mathworks.com/matlabcentral/answers/2103211-how-to-delete-every-alternate-rows#comment_3122001
Akzeptierte Antwort
Naren
am 6 Mai 2024
Hello,
To limit the number of digits after the decimal point to one in the filename, you should modify the sprintf format specifier from %f to %.1f. This will format the floating-point number to have only one digit after the decimal point. Here's how you can do it:
h = 0.5;
writetable(data, sprintf('data_%.1f.txt', h));
In this modified command, %.1f specifies that the floating-point number (h in this case) should be formatted with one digit after the decimal point.
Regards.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Text Analytics Toolbox 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!