I would like to write data in a text file with an alignment of the text after each column head. At this point, here's what I get:
PROJET RECORDER VERSION
Bias RIG001 2.0
Bias RIG002 2.0
Courseulles (eolien) ENR-002 0.1
Monaco ENR-007 3.0
How should I do to align the text after each column head ? I will really appreciate if someone could help me ! Thanks!
NB : Code to process the text file
fid = fopen(fileSave,'w');
fprintf(fid,sprintf('%s%25s%25s\n','PROJET','RECORDER','VERSION'));
for iData = 1:length(logDataName);
fprintf(fid,sprintf('%s%25s%25s\n',logDataName(iData).project,logDataName(iData).recorder,logDataName(iData).version));
end
fclose(fid);

 採用された回答

Stephen23
Stephen23 2015 年 7 月 22 日
編集済み: Stephen23 2015 年 7 月 22 日

0 投票

When you read the fprintf documentation you will find lots of formatting options. Try experimenting with a different format spec, such as using the left justify with a fixed width:
fprintf(fid,'%-25s%-25s%s\n',...)
Also note that you do not need to nest an sprintf inside of the fprintf for this usage: they both accept the same formatting and input strings, so you can simply call the fprintf, as my example shows.

1 件のコメント

justine
justine 2015 年 7 月 22 日
Awesome! It works ! Thanks a lot for your answer :)

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeData Import and Export についてさらに検索

製品

質問済み:

2015 年 7 月 22 日

コメント済み:

2015 年 7 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by