Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
problem in file handling

Subject: problem in file handling

From: seeker_123

Date: 18 Jul, 2013 11:21:10

Message: 1 of 3

hi ....
  I am having problem with file handling

 fident = fopen('aa.txt','r');
 while ~feof(fident)
      op1 = fscanf(fident,'%f',1)
 end
fclose(fident);

here aa.txt contain only 1 value as
1

but my output is for above code is
op1 =

     1


op1 =

     []

is is not exiting on eof for first time
i have checked by printing feof (fident) as
 while ~feof(fident)
      op1 = fscanf(fident,'%f',1)
     eof = feof(fident)
 end

output is
op1 =
     1
eof =
     0
op1 =
     []
eof =
     1

i dont know what is prob

can anyone guide me. i am newbie to matlab

thanks

Subject: problem in file handling

From: someone

Date: 18 Jul, 2013 13:00:14

Message: 2 of 3

"seeker_123" wrote in message <ks8j36$o9h$1@newscl01ah.mathworks.com>...
> hi ....
> I am having problem with file handling
>
> fident = fopen('aa.txt','r');
> while ~feof(fident)
> op1 = fscanf(fident,'%f',1)
> end
> fclose(fident);
>
> here aa.txt contain only 1 value as
> 1
>
> but my output is for above code is
> op1 =
>
> 1
>
>
> op1 =
>
> []
>
> is is not exiting on eof for first time
> i have checked by printing feof (fident) as
> while ~feof(fident)
> op1 = fscanf(fident,'%f',1)
> eof = feof(fident)
> end
>
> output is
> op1 =
> 1
> eof =
> 0
> op1 =
> []
> eof =
> 1
>
> i dont know what is prob
>
> can anyone guide me. i am newbie to matlab
>
> thanks

How do you know FOR SURE that aa.txt contains ONLY one line.
Could the second line simply be a blank, carraige return, line feed or some other non-printing charatcer?

Subject: problem in file handling

From: seeker_123

Date: 19 Jul, 2013 04:44:07

Message: 3 of 3

"someone" wrote in message <ks8osu$9fd$1@newscl01ah.mathworks.com>...
> "seeker_123" wrote in message <ks8j36$o9h$1@newscl01ah.mathworks.com>...
> > hi ....
> > I am having problem with file handling
> >
> > fident = fopen('aa.txt','r');
> > while ~feof(fident)
> > op1 = fscanf(fident,'%f',1)
> > end
> > fclose(fident);
> >
> > here aa.txt contain only 1 value as
> > 1
> >
> > but my output is for above code is
> > op1 =
> >
> > 1
> >
> >
> > op1 =
> >
> > []
> >
> > is is not exiting on eof for first time
> > i have checked by printing feof (fident) as
> > while ~feof(fident)
> > op1 = fscanf(fident,'%f',1)
> > eof = feof(fident)
> > end
> >
> > output is
> > op1 =
> > 1
> > eof =
> > 0
> > op1 =
> > []
> > eof =
> > 1
> >
> > i dont know what is prob
> >
> > can anyone guide me. i am newbie to matlab
> >
> > thanks
>
> How do you know FOR SURE that aa.txt contains ONLY one line.
> Could the second line simply be a blank, carraige return, line feed or some other non-printing charatcer?

thanks

That contain only one data and no new line I have checked
 but problem was solved with
 op1 = fscanf(fident,'%f\n',1)

by putting \n in in scanning solve my issue

thanks to all

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us