Insertion of header in the first row of .txt file
3 views (last 30 days)
Show older comments
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
2 Comments
Accepted Answer
KSSV
on 19 Aug 2020
Edited: KSSV
on 19 Aug 2020
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.
4 Comments
KSSV
on 20 Aug 2020
OP commented:
Hi,
It's working now.. Thanks for the hint..
for k = 1:1:100
filename = sprintf('test%d.txt',k);
fid = fopen(filename,'w');
fprintf(fid, '#DaVis 8.4.0 2D-vector 8 92 112 "position" "mm" "position" "mm" "velocity" "m/s" \n');
fclose(fid);
end
for k = 1:1:100
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, 10304,1);
VVFFF1 = reshape (VFF1,10304,1);
xxx = reshape (X,10304,1);
yyy = reshape (Y,10304,1);
fileName = sprintf('test%d.txt',k);
dlmwrite(fileName,[xxx yyy UUFFF1 VVFFF1],'delimiter','\t','-append');
end
More Answers (0)
See Also
Categories
Find more on Text Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!