Read and search using Textscan

1 Ansicht (letzte 30 Tage)
as hz
as hz am 2 Mai 2013
Hi,
I am reading a long text file using:
fid = fopen('C:\Users\dy4.txt');
s = textscan(fid,'%s');
and I get s 1x1 cell which if I click it I get s{1,1} 120x1 cell, Therefore I have two questions:
- How can I read it to avoid this “cell in cell”?
- The file structure is like that:
10.00000 33.00000
162.00000 55.00000
141.00000 53.00000
1383.00000 39.00000
1565.00000 16.00000
IM=1.jpg
10.00000 83.00000
122.00000 515.00000
121.00000 505.00000
1583.00000 33.00000
1865.00000 46.00000
IM=2.jpg
...
How can I scan the stored cell so I can only output the IM line?
Thanks

Akzeptierte Antwort

Jan
Jan am 2 Mai 2013
Bearbeitet: Jan am 2 Mai 2013
1. You can't. Simply write:
c = textscan(fid,'%s');
s = c{1};
2. strncmp:
lineIndex = strncmp(s, 'IM=', 3); % Or; find(strncmp(...))
matchLine = s(lineIndex);

Weitere Antworten (0)

Kategorien

Mehr zu Large Files and Big Data finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by