MATLAB: Add ‘x,y,z,’ to first line of .txt output

coordinate systemtext file

Hi Folks,
I am working with Matlab code that writes coordinates to a text file as follows:
838959.41800,4713239.59000,1.00000,841305.41800,4708452.59000,1.00000,839175.41800,4712582.59000,1.00000
In the past, I've had to open each file individually and add the following to the first line of the .txt document:
x,y,z, 838959.41800,4713239.59000,1.00000,841305.41800,4708452.59000,1.00000,839175.41800,4712582.59000,1.00000
The following portion of the code I'm working with writes to file:
[flout] = strread(fileName, '%s', 'delimiter','.')
dlmwrite([outputdir 'Coords_' char(flout(1)) '.txt'],Listpos4,'delimiter',',', 'precision', '%.5f');
Any ideas on how to automate this process by embedding code which will write "x,y,z," to the first line of the Matlab .txt output?
Thanks much,
-Aaron

Best Answer

Use fopen(), fprintf(), fclose() to create the file and put the "x,y,z" into it. Then do the dlmwrite() to the file using the -append option.