fscanf
Returns result R after reading a formatted data from file handle, f, specified by template t.
Syntax
R = fscanf(f, t)
R = fscanf(f, t, size)
Inputs
- f
- File handle.
- t
- Template to read formatted data. Valid formats are '%d', '%f', '%g and '%s'.
- size (optional)
- Argument which specifies size of the output. size maybe a positive scalar or a matrix with at least two, positive, real elements. If size is a scalar with a value of 'inf', all data is read and a column vector is returned. If size is a matrix with the second element having a value of infinity, all data is read and returned in a matrix with the number of rows as specified by the first element.
Examples
f = fopen('fscanf1.txt');
R = fscanf(f, '%d/%d/%d %d:%d:%d')
R = [Matrix] 12 x 1
1
1
2001
10
30
0
2
5
2003
1
15
45
f = fopen('fscanf1.txt');
R = fscanf(f, '%f', 3)
R = [Matrix] 3 x 1
5.48813
5.92845
7.15189
f = fopen('fscanf1.txt');
R = fscanf(f, '%d %f %f', [3 10])
R = [Matrix] 3 x 7
1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000
1.77000 1.95000 2.18000 2.75000 3.16000 3.25000 2.86000
0.96000 0.83000 0.65000 1.42000 5.53000 4.19000 2.82000
f = fopen('fscanf1.txt');
R = fscanf(f, '%d %f %f', [10 inf])
R = [Matrix] 10 x 2
1.00000 2.75000
1.77000 1.42000
0.96000 5.00000
2.00000 3.16000
1.95000 5.53000
0.83000 6.00000
3.00000 3.25000
2.18000 4.19000
0.65000 7.00000
4.00000 2.86000