Removing first row from .txt files and convert them to .csv format in one folder
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Mathew Smith
am 14 Dez. 2023
Beantwortet: Dyuman Joshi
am 14 Dez. 2023
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 Kommentare
Akzeptierte Antwort
Dyuman Joshi
am 14 Dez. 2023
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Text Files finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!