Insertion of header in the first row of .txt file
7 次查看(过去 30 天)
显示 更早的评论
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
采纳的回答
KSSV
2020-8-19
编辑:KSSV
2020-8-19
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 个评论
KSSV
2020-8-20
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!