We recommend readtable() for this purpose.
If you use fscanf() then you have the problem that when you mix %s format (for the text) with numeric format, then the characters are emitted as numbers, and there is no boundary emitted so you cannot reliably tell where the characters end and the numbers begin. In order to handle the above situation with fscanf() you would need one of the following approaches:
- loop asking to fscanf() with format '%s' and size 1, and take char() of the result to get the first column, then fscanf format '%f%f%f%f' and size [1 4] to read the numeric columns, then back to the beginning of the loop; OR
- fscanf with format %*s%f%f%f%f and no size, to read all of the numeric data, after which you would frewind() to return to the beginning of the file and proceed to use a different fscanf to read the text
These kinds of problems go away if you use readtable() or textscan()