MATLAB: Insertion of header in the first row of .txt file

#header insertion txt filedlmwritetxt file

Hi,
I need to insert below header file in the first row of the each txt file, please assist me in how to do this..
#DaVis 8.4.0 2D-vector 12 62 75 "position" "mm" "position" "mm" "velocity" "m/s"
for k = 1:1:5
UFF = X_filter(1:ni*nk,k);
VFF = X_filter(1+ni*nk:2*ni*nk,k);
UFF1 =reshape (UFF,ni,nk)';
VFF1 =reshape (VFF,ni,nk)';
UUFFF1 = reshape (UFF1, 4650,1);
VVFFF1 = reshape (VFF1,4650,1);
xxx = reshape (X,4650,1);
yyy = reshape (Y,4650,1);
fileName = sprintf('test%d.txt',k);
dlmwrite(fileName,[xxx yyy UUFFF1 VVFFF1],'delimiter','\t' );
end

Best Answer

Something like this should work.
filename = 'test2.txt';
fid = fopen(filename,'w');
fprintf(fid, 'HEADER \n');
fclose(fid);
for k = 1:1:5
UFF = X_filter(1:ni*nk,k);
VFF = X_filter(1+ni*nk:2*ni*nk,k);
UFF1 =reshape (UFF,ni,nk)';
VFF1 =reshape (VFF,ni,nk)';
UUFFF1 = reshape (UFF1, 4650,1);
VVFFF1 = reshape (VFF1,4650,1);
xxx = reshape (X,4650,1);
yyy = reshape (Y,4650,1);
fileName = sprintf('test%d.txt',k);
dlmwrite(fileName,[xxx yyy UUFFF1 VVFFF1],'delimiter','\t','-append');
end
dlmwrite is obselete.....read about writematrix.
Related Question