Error In Printing NaN Data to .txt

조회 수: 1(최근 30일)
Tyann Hardyn
Tyann Hardyn 2022년 8월 21일
댓글: dpb 2022년 8월 21일
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:
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
dpb
dpb 2022년 8월 21일
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.

댓글을 달려면 로그인하십시오.

답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by