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 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Angela Bowman
el 19 de Jun. de 2015
Comentada: Angela Bowman
el 19 de Jun. de 2015
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 comentarios
Respuesta aceptada
Azzi Abdelmalek
el 19 de Jun. de 2015
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);
Más respuestas (0)
Ver también
Categorías
Más información sobre Text Files en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!