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: troubles with fscan
Replies: 5   Last Post: Jan 3, 2011 8:30 PM

Advanced Search

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

Posts: 191
Registered: 9/9/08
Re: troubles with fscan
Posted: Jan 3, 2011 12:17 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Lucie Van Hove" wrote in message <ifrj8l$env$1@fred.mathworks.com>...
> I have a problem with fscanf, and I know it will be something stupid, but I have read all the documentation and I cannot find the solution.
>
> I have a textfile with this format:
> aaaa
> bbbb
> cccc
> dddd
>
> I want to read this in to Matlab in a vector.
> But if I do
> fid = fopen('file.txt','r');
> if (fid < 0)
> error('could not open file "file.txt"');
> end;
> A = fscanf(fid,"%s",[1,inf])
>
> Then I get
> A = aaaabbbbccccdddd
> And that is obviously not what I want.
>
> Can anybody help me? Thanks


Hi,

If you want it to be like a line by line
try using "textscan" with delimiter option as (\n).

you get it in a cell array with each line in one cell.

Shan!



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

[Privacy Policy] [Terms of Use]

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