Comma separated data with text

Hello,
I have a problem with making a .txt-file with both comma separated data and some text. I really hope some experts out there can help me.
I have the following data in MATLAB:
x=1:10.
These data have to be comma separated so I have looked at the commands csvwrite and dlmwrite. The problem is that I have to add some text in the exported .txt-file. An example of this is a .txt-file containing:
Hello 1,2,3,4,5,6,7,8,9,10 This is the data.
I hope this makes sense. And that someone can help me.
Hope to hear from you.

 採用された回答

Jan
Jan 2012 年 5 月 14 日

3 投票

x = 1:10;
fid = fopen('FileName.txt', 'w');
if fid == -1; error('Cannot open file for writing'); end
fprintf(fid, 'Hello ');
fprintf(fid, '%g, ', x(1:end-1));
fprintf(fid, '%g', x(end));
fprintf(' %s\n', 'This is the data.');
fclose(fid);

2 件のコメント

Martin
Martin 2012 年 5 月 14 日
Thank you - just what I needed. Really appreciate it.
Jan
Jan 2012 年 5 月 14 日
If this answer solves your problem, voting or accepting it is the standard procedure to tell others, that no further help is required.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLarge Files and Big Data についてさらに検索

質問済み:

2012 年 5 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by