Need help parsing text from .txt file
1 view (last 30 days)
Show older comments
I have some data that has header text followed by 7 columns of data of variable length. This data consists of multiple tests in a file, so this repeats itself with another row of header text and then more data. I've attached some sample data. I need to get the data in to individual arrays for each test and have the header text assigned to a variable. I've tried to use readtable() and textscan(), but can't figure out how I can separate the arrays apart and extract the header text from the file.
Any help would be greatly appreciated
1 Comment
Cris LaPierre
on 30 Sep 2020
You've included an image rather than attaching your data. Use the paperclip icon to share a sample of your data with us.
Answers (1)
Cris LaPierre
on 30 Sep 2020
One way to skip a specific line in a file is to read it line by line and check the contents first. Here's a quick example using a simple data set.
fid = fopen("sampleTest.txt");
data = [];
while ~feof(fid)
l=fgetl(fid);
if ~strcmp(l,'"TEST NAME EXAMPLE"')
data(end+1,:) = str2double(strsplit(l));
end
end
fclose(fid)
0 Comments
See Also
Categories
Find more on Text Data Preparation 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!