Removing first row from .txt files and convert them to .csv format in one folder
4 次查看(过去 30 天)
显示 更早的评论
Hello,
I would like to to convert all txt file in a folder to .csv format without header. I went through various solutions on this forum and they worked only partially or not at all.
I would like to ask you for help.
File 1:
X Location (m) Y Location (m) Z Location (m) Temperature (°C)
0.218899995 0.197255 -3.89899989e-003 22.
0.21783933 0.197255 -4.33835154e-003 22.
0.217399999 0.197255 -5.39901108e-003 22.
0.217839345 0.197255 -6.45966409e-003 22.
File 2:
X Location (m) Y Location (m) Z Location (m) Temperature (°C)
0.218899995 0.197255 -3.89899989e-003 22.
0.21783933 0.197255 -4.33835154e-003 22.
0.217399999 0.197255 -5.39901108e-003 22.
0.217839345 0.197255 -6.45966409e-003 22.
Best regards
Michal
0 个评论
采纳的回答
Dyuman Joshi
2023-12-14
Here is a general way of reading data from multiple files and performing operations on it.
I have changed the temperature values of the 2nd file to show as an example.
%Get all the files in the folder ending with .txt format
%Update the search text if there is a unique string related to all files
files = dir('*.txt')
%Run a for loop through all the files
for k=1:numel(files)
%Get the full path to the file
fullname = fullfile(files(k).folder, files(k).name);
%Read the data via readmatrix()
%As the output will only contain numeric values, not the text header
in = readmatrix(fullname);
%Write the data as a csv file, by changing the extension of the file
writematrix(in, replace(fullname, '.txt', '.csv'));
end
%Checking the output
type('File1.csv')
type('File2.csv')
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!