|
Use textread and then extract the items you need by doing pattern search through regexp function -
Say, your file is called list.txt ,
x=textread('list.txt','%s','delimiter','\n')
x =
'1'
'2'
'dog'
'25'
'old str1'
'old str2'
'old str3'
'24 25'
'cat banana'
'1'
'2 bears is a lot of bears'
'3'
mypattern=regexp(x,'^old') %my pattern is also a cell array
mypattern =
[]
[]
[]
[]
[1]
[1]
[1]
[]
[]
[]
[]
[]
j=find(~cellfun('isempty',mypattern))
j =
5
6
7
answer = x(j)
answer=x(j)
answer =
'old str1'
'old str2'
'old str3'
"Johnathan " <durchfalldurchfall@yahoo.com> wrote in message <guap0v$5a9$1@fred.mathworks.com>...
> if i have a file like
>
> 1
> 2
> dog
> 25
> old str1
> old str2
> old str3
> 24 25
> cat banana
> 1
> 2 bears is a lot of bears
> 3
>
> and so forth, all mixed up, and I want to read the lines that say:
> old str1
> old str2
> old str3
>
> with the intention of obtaining the strings, how do I do that?
> I looked at textscan, and it works if the file is not so jumbled, but I can't get it to sort through a messy file. if I say A=textscan(fid,'old %s') I get that
> A =
> {0x1 cell}
>
> What can I do?
>
> Thanks
|