Error In Printing NaN Data to .txt

1 view (last 30 days)
Tyann Hardyn
Tyann Hardyn on 21 Aug 2022
Commented: dpb on 21 Aug 2022
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]') ;
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:
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 Comment
dpb on 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)
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.

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!