Pull out certain strings from a text file

I am trying to pick out the lines start and end in the below file.
I search to find the string in red, and want to pull out the data in green. the number of rows varies.
This is my code so, far. I can find the line that contains the text in red, but then don't know how to proceed.
searchstr='Number of Regions';
fid = fopen(file,'r');
ct=0;
linect=0;
A=[];
Count=[];
while 1
tline = fgetl(fid);
linect=linect+1;
if strfind(tline, searchstr)>0
linect
tline
ct=ct+1
end
if ~ischar(tline)
break
end
end

댓글 수: 1

fmt=[repmat(1,6,'%*s' repmat(1,4,'%f') '%*[^\n]'];
cac = textscan(fmt, 'Headerlines', 2,'collectoutput',1);
I almost always for all-numeric data wrap the call in cell2mat to get the array instead of cell array...
cac = cell2mat(textscan(fmt, 'Headerlines', 2,'collectoutput',1));

댓글을 달려면 로그인하십시오.

답변 (1개)

Sean de Wolski
Sean de Wolski 2014년 12월 22일

0 개 추천

Just use the import tool:
  • Right click on the file in the current folder browser
  • Select "Import Data"
  • Select the data you want to bring in, how you want to bring it in, etc. and hit import or generate script (under import)

카테고리

도움말 센터File Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

질문:

2014년 12월 22일

답변:

2014년 12월 22일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by