Section: Input/Ouput Functions
A = fread(handle,size,precision)
The handle
argument must be a valid value returned by the fopen
function, and accessable for reading. The size
argument determines
the number of values read from the file. The size
argument is simply
a vector indicating the size of the array A
. The size
argument
can also contain a single inf
dimension, indicating that FreeMat should
calculate the size of the array along that dimension so as to read as
much data as possible from the file (see the examples listed below for
more details). The data is stored as columns in the file, not
rows.
Alternately, you can specify two return values to the fread
function,
in which case the second value contains the number of elements read
[A,count] = fread(...)
where count
is the number of elements in A
.
The third argument determines the type of the data. Legal values for this
argument are listed below:
512 x 512
Gaussian-distributed float
random variables, and then writing them to a file called test.dat
.
--> A = float(randn(512)); --> fp = fopen('test.dat','wb'); --> fwrite(fp,A); --> fclose(fp);
Read as many floats as possible into a row vector
--> fp = fopen('test.dat','rb'); --> x = fread(fp,[1,inf],'float'); --> who x Variable Name Type Flags Size x float [1 262144]
Read the same floats into a 2-D float array.
--> fp = fopen('test.dat','rb'); --> x = fread(fp,[512,inf],'float'); --> who x Variable Name Type Flags Size x float [512 512]