The Math Forum



Search All of the Math Forum:

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


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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: fgetl consuming huge time
Replies: 1   Last Post: Jan 14, 2009 1:26 PM

Advanced Search

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

Posts: 384
Registered: 1/12/09
Re: fgetl consuming huge time
Posted: Jan 14, 2009 1:26 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Pratap " <satya_p75@yahoo.com> wrote in message <gkl939$9jh$1@fred.mathworks.com>...
> Hi
>
> I would like to read a txt file which looks something like this.
>
> 1 2 3 4 5
> 1 2
> 1 2 3 4 5 6 7 8 9 0
> . .......
> 1 2 3 4 5
> 12
> MA MB MC MD
> I have already done this read using fgetl command. But it is quite slow when my file is huge.
>
> Does any one has any other fix to this problem? Please le me know I will appreciate it
>
> Thanks


Hellp Pratap,

Please use the following: [assuming that your file name is myFile.txt]

fid = fopen('C:\myFile.txt','r');
A = textscan(fid,'%s','delimiter','\n');

For the example you gave, this will return a cell array with each element comprising each line in the file. So, if you would like to access the third line, you should type:

thirdLine = A(3){:};

thirdLine will be the string '1 2 3 4 5 6 7 8 9 0'.

Hope this helps.



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

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.