Tuesday, April 5, 2011

Q. How the hell do I write a matlab text file with a header?

A.
filename = [filename '_back.txt']
fid = fopen(filename,'w+')
header = ['m4, m1, m2, m3, m5']
fprintf(fid,'%s\n',header)
fclose(fid);

The trick is the %s which writes a string instead of just one character at a time.. otherwise you'll end up with comma's between every letter. There goes two hours of my life :(

No comments: