MATLAB: How to read data from a file that has an unknown format

MATLAB

I have a file that contains some data, but I do not know the exact format of the data.

Best Answer

In general, it is not possible to read the contents of a file without knowing the file's format, because one needs to know how to interpret the bits that comprise the file in order to understand the data that it contains.
That said, it is sometimes possible to determine what format a file is in--or at least what format the file is probably in--by guessing the a format and checking whether:
1. The file is readable in that format (whether it "fits" that format), and
For instance, if you suspect your file may consist of a series of IEEE double precision numbers, you can check if the number of data bits contained by the file is a multiple of 64. If not, this cannot be the file's format.
2. Whether the data obtained by assuming that format is reasonable.
Suppose you know that a file does consist of a series of IEEE double precision numbers, but do not know whether they are big- or little-endian. If your know something about the meaning of these numbers, it is likely that assuming one of these formats will result in "reasonable" numbers and the other results in "unreasonable" numbers.
Note that these two things do not guarantee you have identified the correct format. It is possible that the same file can be read assuming two different formats and "reasonable"--but different--data is obtained in each case. In many cases, however, this is unlikely.