To combine DateTime and data, they both need to be cell arrays, because one of them contains strings. This will work to produce a combined array
combined = [DateTime, num2cell(data)];
However, that won't solve your problem, because you can't write a cell array with dlmwrite.
One possibility is to do something like the code below, using fprintf to do the tab-separated data. Note that this code uses the original numerical data matrix, and that you may need to fiddle with the format for the numbers to get the precision you need.
outfile = 'path/output.out';
header = { ...
' DateTime', ...
'data1','data2','data3','data4', ...
'data5','data6','data7','data8', ...
'data9','data10','data11','data12'};
fid = fopen(outfile, 'w');
if fid == -1; error('Cannot open file: %s', outfile); end
fprintf(fid, '%10s\t', header{:});
fprintf(fid, '\n');
for ii = 1:size(data, 1)
fprintf(fid, '%s\t', DateTime{ii});
fprintf(fid, '%10.6g\t', data(ii,:));
fprintf(fid, '\n');
end
fclose(fid);
Best Answer