Thanks for providing the code, I just integrated it into a project I'm working on. I've also extended the code a bit to add automatic folder creation when the filename target folder doesn't exist. See:
Feel free to integrate my changes into the code here, if you feel they are of general interest.
01 Feb 2014
CSV with column headers
This simple routine extends the function of the MATLAB csvwrite function to add column headers
Added a few lines to get the precision to behave with arbitrary inputs:
DP=2; % DECIMAL PLACES:
dlmwrite(filename, m,'-append','delimiter',',','precision', prec, 'roffset', r,'coffset',c);