Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: reading the previous line in a text file
Replies: 4   Last Post: Dec 13, 2010 12:39 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Ali

Posts: 18
Registered: 12/11/10
reading the previous line in a text file
Posted: Dec 12, 2010 7:37 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

use txtscan instead of fgetl like this:

fid = fopen(InputFile);
txtData = textscan(fid,'%[^\n\r]');
txtData = txtData{:};
fclose(fid);

this saves the whole file in a cell array... each line in a cell of the array.. you can choose the line you want by using its index.
ALi

"Peli " <bogus88@gmail.com> wrote in message <ie2epd$r06$1@fred.mathworks.com>...
> I need to read a large text file and use only certain lines.
> I can decide wether I need a line only by using information in the next line.
>
> line
> line
> will need this line data 1323 34 23 53425
> use the previous line
> line
> line
>
> I read the text using "fopen" and "fgetl".
> how can I read the previous line in the text (in relation to the file fid)?
>
> file_fid=fopen('textfile.txt', 'r');
> tline=fgetl(file_fid);




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2013. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.