How do I write variables to a text file with date string in format mm/dd/yyyy and three columns of numerical data and add headers?
2 ビュー (過去 30 日間)
古いコメントを表示
I have several variables I want to write to a text file, where the resulting .txt file will be: col1 = time (in cell array of size 5844:1 with format mm/dd/yyyy); col2 = var1; col3 = var2; col4 = var3.
I am having trouble with the date column and cannot seem to correctly write it to the .txt file. I have used fprintf and dlmwrite but I am not understanding how to write string to text. Also, how do I add header? Please help! Angela
0 件のコメント
採用された回答
Azzi Abdelmalek
2015 年 6 月 19 日
date=datestr(datenum('10/01/2014'):datenum('10/10/2014'),'dd/mm/yyyy')
var1=(1:10)'
var2=sin(var1)
header='date var1 var2'
M=[cellstr(date) num2cell(var1) num2cell(var2)]
fid = fopen('fic.txt','w');
myformat='%s %12.4f %12.4f \r\n'
fprintf(fid,'%s\r\n',header);
for k=1:size(M,1)
fprintf(fid,myformat,M{k,:})
end
fclose(fid);
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Text Files についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!