Import from data from messy text file
显示 更早的评论
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.
采纳的回答
更多回答(1 个)
Shameer Parmar
2016-7-28
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);
类别
在 帮助中心 和 File Exchange 中查找有关 Text Data Preparation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!