Error In Printing NaN Data to .txt
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi Community,
I have a question about printf function in Matlab. Iam using printf function like this below:
hasil_convs_saving_mult = sprintf('Fixed %s Combined Magnetic Data %s %s (%s).txt', savektot_data, mr_mm_tot, convtot_begins_finals, stasiunc_comb);
saving_multfileconvs = fullfile(pathraw, hasil_convs_saving_mult);
foutsaving_multfileconvs = fopen(saving_multfileconvs,'w');
fprintf(foutsaving_multfileconvs,'%s %s %s %s %s %s %s %s %s %s %s %s\n', 'DATE', 'TIME', 'H(Fix)', 'F(Calc_Fix)', 'F(Obs_Fix)', 'D(Fix)', 'X(Fix)', 'Y(Fix)', 'Z(Fix)', tipec_comb, stasiunc_comb, time_conversion);
fprintf(foutsaving_multfileconvs,'%s %s %.2f %.2f %.2f %.2f %.2f %.2f %.2f\n', [waktudate_conv_combi, waktutime_conv_combi, Total_ekstrak_komph, Total_ekstrak_kompfcalc, Total_ekstrak_kompfobs, Total_ekstrak_kompd, Total_ekstrak_kompx, Total_ekstrak_kompy, Total_ekstrak_kompz]') ;
fclose(foutsaving_multfileconvs);
However, the output is so weird. The output of the above code is actually in .txt, but when i opened it in notepad..... It sadly become like this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1103350/image.png)
Why the ouput become like this, everyone... I realized that the data input was include NaN data in double, but it never like this before.... Would anyone lend me a hand to solve this problem? Is it because of my PC setting or an Error in my code or what? Thank you so much.... /.\ /.\ /.\
1 Kommentar
dpb
am 21 Aug. 2022
Don't use Notepad; try the MATLAB editor -- but looks like an issue with default fonts, maybe. I think fprintf handles NaN, ...well, let's just refresh memory...
>> fprintf('%d\n',nan)
NaN
>>
yes, as I remembered (and has to be)...
There's may be something else going on with what the actual data are, as well and a formatting issue of char() and numerics with correct matching formatting strings -- although MATLAB does its best to create a matching output.
Antworten (0)
Siehe auch
Kategorien
Mehr zu Characters and Strings 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!