sscanf
Returns result R after reading a formatted string s, specified by template t.
Syntax
R = sscanf(s, t)
R = sscanf(s, t, size)
Inputs
- s
- String to read formatted data from.
- 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.
Outputs
- R
- Type: matrix
Examples
Reads all data from given string:
R = sscanf('1/1/2001 10:30:00 2/5/2003 1:15:45', '%d/%d/%d %d:%d:%d')
R = [Matrix] 12 x 1
1
1
2001
10
30
0
2
5
2003
1
15
45
R = sscanf('5.48813502420671 5.92844616505317 7.15189365088008 8.44265744206496 6.02763370494358', '%f', 3)
R = [Matrix] 3 x 1
5.48813
5.92845
7.15189
R = sscanf('1 1.77 0.96 2 1.95 0.83 3 2.18 0.65 4 2.75 1.42 5 3.16 5.53 6 3.25 4.19 7 2.86 2.82', '%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
R = sscanf('1 1.77 0.96 2 1.95 0.83 3 2.18 0.65 4 2.75 1.42 5 3.16 5.53 6 3.25 4.19 7 2.86 2.82', '%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