MATLAB: How to Read specific parts(formatted) of an unformatted text file

MATLABread specific parts of unformatted text file;textscan

Hi guys,
I got confused about reading specific parts of an unformatted text. My text is something like this :
First 50(this number can vary) rows are in different length and consist of stings and number..
Then a specific pattern comes, and let say it is:
0 Alpha Beta A B C D E F G H I K
I want the skip the next and read the next 20(this number can change too) rows and 12 columns that consist of numbers.
Then I want to skip the lines till I met
0 X Y Z K L M N P R
I want the skip the next and read the next 20(this number can change too) rows and 9 columns that consist of numbers.
(Columns are tab separated)
I got very confused. Can any one Help me ?

Best Answer

Just read and ignore 'til you find the specific stuff looking for...*regexp* can do this or you can just read and test...
fid=fopen('yourfile.txt','r');
j=0; % counter for data cells found
while ~feof(fid) % go to end
l=fgetl(fid); % read a line
if isempty(strfind(l(2:end),'ALPHA')),continue,end % skip if not what want
j=j+1; % increment the counter
title(j)=cellstr(l(3:end)); % title line w/o leading '0'
data{j}=textscan(fid,repmat('%f',1,9),'collectoutput',1,'headerlines',1); % read data
end
fid=fclose(fid);
% do whatever with data in the resulting cell array
...