reading ascii data

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

reading ascii data

de Almeida, Valmor F.

Hello,

I would like to read an ascii data file with 3 columns of integers
separated by a space, and an unknown number of rows into 3 vectors or a
matrix with 3 columns.

I have tried

[a,b,c,count] = fscanf(fid,"%i %i %i","C");

But this only reads one row of the file and I have to put it into a
while loop with an eof check. Is this a correct assessment?

Alternatively,

[val,count] = fscanf(fid,"%i %i %i");

reads the whole file as a column vector. I could break up the vector
into 3 vectors or a matrix with 3 columns but I wonder if this could be
done by the file reader function itself.

Thanks,

--
Valmor



_______________________________________________
Help-octave mailing list
[hidden email]
https://www.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: reading ascii data

bpabbott
Administrator

On Tuesday, August 05, 2008, at 12:29PM, "de Almeida, Valmor F." <[hidden email]> wrote:
>
>Hello,
>
>I would like to read an ascii data file with 3 columns of integers
>separated by a space, and an unknown number of rows into 3 vectors or a
>matrix with 3 columns.

Try

     data = load ("-ascii",  "yourfile.txt")

Ben
_______________________________________________
Help-octave mailing list
[hidden email]
https://www.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: reading ascii data

Rubén Roa-Ureta
In reply to this post by de Almeida, Valmor F.
de Almeida, Valmor F. wrote:

> Hello,
>
> I would like to read an ascii data file with 3 columns of integers
> separated by a space, and an unknown number of rows into 3 vectors or a
> matrix with 3 columns.
>
> I have tried
>
> [a,b,c,count] = fscanf(fid,"%i %i %i","C");
>
> But this only reads one row of the file and I have to put it into a
> while loop with an eof check. Is this a correct assessment?
>
> Alternatively,
>
> [val,count] = fscanf(fid,"%i %i %i");
>
> reads the whole file as a column vector. I could break up the vector
> into 3 vectors or a matrix with 3 columns but I wonder if this could be
> done by the file reader function itself.
>
> Thanks,
>
> --
> Valmor
>  
For this job I use load, such as in:
a = [1,2,3;4,5,6;7,8,9]
save -ascii a.txt a
b = load a.txt
b =
   1   2   3
   4   5   6
   7   8   9
HTH
Ruben
_______________________________________________
Help-octave mailing list
[hidden email]
https://www.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

RE: reading ascii data

de Almeida, Valmor F.
In reply to this post by bpabbott

Thanks. It does work.

--
Valmor


> -----Original Message-----
> From: Ben Abbott [mailto:[hidden email]]
> Sent: Tuesday, August 05, 2008 1:59 PM
> To: de Almeida, Valmor F.
> Cc: [hidden email]
> Subject: Re: reading ascii data
>
>
> On Tuesday, August 05, 2008, at 12:29PM, "de Almeida, Valmor F."
> <[hidden email]> wrote:
> >
> >Hello,
> >
> >I would like to read an ascii data file with 3 columns of integers
> >separated by a space, and an unknown number of rows into 3 vectors or
a
> >matrix with 3 columns.
>
> Try
>
>      data = load ("-ascii",  "yourfile.txt")
>
> Ben

_______________________________________________
Help-octave mailing list
[hidden email]
https://www.cae.wisc.edu/mailman/listinfo/help-octave