Import from data from messy text file
Show older comments
Hi, I have looked through the questions and answers that are already available for this topic but wasn't able to apply those to my situation.
For the attached file, I need to extract the data for each "Specimen." The data that i need are the three columns corresponding to the 500+ rows for each specimen. If possible, I would like to save it in to different arrays. One for each specimen.
Accepted Answer
More Answers (1)
Shameer Parmar
on 28 Jul 2016
Here is that can help you..
Data = textread('SAMPLE_DATA.txt', '%s', 'delimiter', '');
count=1;
newData = {};
for i=1:length(Data)
if ~isempty(strfind(Data{i},','))
newData{count,1} = Data{i};
count=count+1;
end
end
count1=1;
count2=0;
Specimen = {};
for i=1:length(newData)
linedata = newData{i};
if ~isempty(strfind(linedata(1:2),'1,'))
count2=count2+1;
count1=1;
Specimen{count1,count2} = linedata;
else
count1=count1+1;
Specimen{count1,count2} = linedata;
end
end
to check the output
type
Specimen(:,2);
Categories
Find more on Text Data Preparation in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!