How do I add text to the top of a CSV file?

8 ビュー (過去 30 日間)
David Coathup
David Coathup 2019 年 9 月 9 日
コメント済み: David Coathup 2019 年 9 月 11 日
I need to export a table as a CSV file, but I also need to add some text across several rows above the main table. Idealy, my output data should look like this:
string
string
string
NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN
I can get the tabelised data to be saved as .csv file, but I can't find away to get the text I need to also be inserted into the rows above the main text aswell. How do I do this?

採用された回答

Bob Thompson
Bob Thompson 2019 年 9 月 9 日
編集済み: Bob Thompson 2019 年 9 月 9 日
The best way I have found to do this is with a combination of fprintf and dlmwrite. While csvwrite is nice for writing out the data, it does not work well with writing text.
The basic form of what you are trying to do should look something like the following:
fo = fopen('fileout.csv');
fprintf(fo,'%c',string);
fclose(fo);
dlmwrite('fileout.csv',data,'-append');
There are some newer commands you can use in place of dlmwrite, and you can replace fprintf with sprintf or similar, but the basic concept is the same.
  1 件のコメント
David Coathup
David Coathup 2019 年 9 月 11 日
Hi Bob,
I got it wo work using this script, thank you very much.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCell Arrays についてさらに検索

製品


リリース

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by