Mat = fscanf( fid, ' %f %f ', [2, M] );
read next M rows of numbers into matrix 'Mat'
each column of file goes to a row in Mat,
then we can extract rows from 'Mat'
2 = number of columns in file,
M = #of rows (best is to use: [2, inf] to read all remaining rows ).
Example data file: 'mydata.dat' contains:
# mydata.dat: date, description, ...
# x y
1 31
2 32
3 33
To read it into an array "XY":
fid = fopen('mydata.dat', 'r')
while( ~feof(fid) )
Line = fgetl(fid); read over 1st line of words
Line = fgetl(fid); read over 2nd line of words
XY = fscanf( fid, ' %f %f', [2, inf] );
end %while, file has been read
Then matrix 'XY' will be:
1 2 3
31 32 33
and we can extract each row, say for plotting:
x = XY(1,:); y = XY(2,:);
plot( x, y )