Why does a .dat file look good in Matlab, then open with incorrect formatting externally??

Hi All,
As per the title, this short script:
for i = 1:length(X)
fid = fopen(['LUKE_',num2str(i),'.dat'],'w');
fprintf(fid, ['LUKE''s blade design, element number ',num2str(i),'\n']);
fprintf(fid, 'data here NOT from PROPID \n')
fprintf(fid, '1 \n') %No. airfoil tables in this file
fprintf(fid, [num2str(i),'\n']) %table ID parameter
fprintf(fid, '13 \n') %stall angle
fprintf(fid, '0 \n') %not used
fprintf(fid, '0 \n') %not used
fprintf(fid, '0 \n') %not used
fprintf(fid, '-4.245 \n') %Angle of attack for zero Cn for linear Cn curve (deg)
fprintf(fid, '6.009 \n') %Cn slope for zero lift for linear Cn curve (1/rad)
fprintf(fid, '1.809 \n') %Cn at stall value for positive angle of attack for linear Cn curve
fprintf(fid, '-1 \n') %Cn at stall value for negative angle of attack for linear Cn curve
fprintf(fid, '0 \n') %Angle of attack for minimum CD (deg)
fprintf(fid, '0.01072 \n') %Minimum CD value
for k = 1:length(AERO_ANG)
fprintf(fid,'%-8s',num2str(AERO_ANG(k)));
fprintf(fid,'%-8.6s',num2str(AERO_CL(k,i)));
fprintf(fid,'%-8.7s\n',num2str(AERO_CD(k,i)));
end
fclose(fid)
end
Output looks as expected when 'opened as text' in Matlab. This is not the case when opened externally. Could someone please explain why?
Thanks,
Pascal

 採用された回答

Walter Roberson
Walter Roberson 2012 年 4 月 3 日

2 投票

If you need to open in NotePad, then change the 'w' in the fopen() to 'wt' .

2 件のコメント

Geoff
Geoff 2012 年 4 月 4 日
+1 : this solution is platform-independent.
Jan
Jan 2012 年 4 月 4 日
Another platform independent solution is deleting NotePad and use any other editor. I associate text files with WordPad or NotePad++ on every Wondows machine I have to administrate.
Anyhow, Walter, I agree that here 'wt' is a working solution. +1
Using '\r\n' would create the identical files under Linux.

サインインしてコメントする。

その他の回答 (3 件)

Jason Ross
Jason Ross 2012 年 4 月 3 日

0 投票

When you are opening the file externally, what are you using? It could look "incorrect" if you are opening it in a program that uses a non-monospaced font.
I'm assuming that "incorrect" means "the stuff doesn't line up". If that's not it, please clarify what you mean by "incorrect"
Pascal Galloway
Pascal Galloway 2012 年 4 月 4 日

0 投票

Thanks guys! The 'wt' works perfectly! Just to clarify Jason's comment, I do mean incorrectly lining up when using notepad.

カテゴリ

ヘルプ センター および File ExchangeConstruct and Work with Object Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by