I'm trying to get a loop to write headers between matrices to a .txt file from matlab.
Example code:
filename = 'sampleXLS.dat';datfile = fopen(filename,'w');header = 'Header \n';mat1 = [1,2,3;4,5,6]; mat2 = [7,8;9,10];mat3 = [11;12;13];mats = {mat1,mat2,mat3};for iter = 1:length(mats) data = mats{iter} fprintf(datfile, header); dlmwrite(filename, data,'-append','delimiter',' ','precision', '%f');end
I want
Header1 2 34 5 6 Header7 89 10Header 111213
I am getting
HeaderHeaderHeader 34 5 6 7 89 10111213
Note the missing 1 and 2, when I step though the file in debug mode it is inserting and replacing the numbers with the headers as it goes along.
Is there a way to tell fprintf to append?
Best Answer