function writeCsvMerfish(name,titleCell,dat)

title=strjoin(titleCell,',');

fid = fopen(name,'w'); 
fprintf(fid,'%s\n',title)
fclose(fid)

%write data to end of file
% dlmwrite('yourfile.csv',dat,'-append');

writematrix(dat,name,'WriteMode','append');