Files and Data Structures
Files and Data Structures
fid if no error
BINARY FILES
File size (precision)
count=fwrite(fd,var,precision)
Writes the elements of the variable var to the specified file fd , translating the value to the
specified precision (optional).
It reads the number of elements specified by size in the binary format specified by precision. The
read value is stored in var.
TEXT FILES
FILE WRITING USING fprintf ()
Count = fprintf(fd,format,var1,…)
It applies the format to all elements of var1 (IN TEXT FORM) and any additional arguments and
writes the data to a text file.
FORMAT QUALIFIERS
FILE READING USING fscan ()
[var,count]=fscanf(fd,format,size)
Return value:
Count: is an optional output argument that returns the number of elements successfully read.
FUNCTION feof ()
st=feof(fd)
Test for end-of-file. It returns 1 if the end-of-file indicator for the file with file identifier fd has
been set, and 0 otherwise. The end-of-file indicator is set when a read operation on the file
associated with the FID attempts to read past the end of the file.
DATA STRUCTURES
STRUCTS: they are compound of data types structured in
field → used to store non-homogeneous data types.
ARRAYS OF STRUCTS: each element of an array can be an struct and can be accesses as follows:
CELL ARRAYS:
Problem with arrays : arrays of elements of different sizes → SOLUTION: using cell arrays, they are
defined using {}: