reading ascii data

Rubén Roa-Ureta rroa at udec.cl
Tue Aug 5 14:19:52 CDT 2008


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


More information about the Help-octave mailing list