Read .txt file into a matrix and remove unwanted text
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Justin Rosenthal
am 5 Jan. 2022
Kommentiert: Justin Rosenthal
am 5 Jan. 2022
Hello,
I have a .txt file that I want to simplify into a matrix. I want to remove the first 3 lines completely, keep the numbers in the first row without the decimal places or colon (i.e. 6248.2: should become 6248) and I want to keep the key words in the last column such as flush-evac, flush, etc. I would also like the remove the line in the middle of the file that starts with a #. I'm pretty sure that textscan can accomplish this task but I am struggling with acquiring the correct format. Any help would be greatly appreciated.
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (1)
Voss
am 5 Jan. 2022
fid = fopen('N2_trace.txt');
data = fread(fid);
fclose(fid);
c_data = strsplit(char(data).',newline());
if isempty(c_data{end})
c_data(end) = [];
end
c_data(1:3) = [];
time = cellfun(@(x)str2double(x(1:find(x == '.',1)-1)),c_data);
status = cellfun(@(x)x(find(x == ':',1,'last')+2:end),c_data,'UniformOutput',false);
disp(c_data);
disp(time);
disp(status);
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!