Feb 012010
One of the most common things I do in Matlab almost always involves reading in binary data. For a few years I went through the typical fp=fopen('filename.dat'.... After typing the fopen, fread, reshape and fclose too many times, I finally made it into an all-in-one Matlab function called readraw() which will do all the reading and reformatting in one function call.
1 2 3 4 5 6 7 8 9 10 11 |
There isn’t much magic here, just a simple idea that I use almost daily.



Something that I found is that the endian will change depending on the machine that you use to read/write your data. FSL, for example, uses the computer’s default endian-ness. I have the same function, but my beginning is:
if (nargin == 3)
[str,maxsize,endian] = computer;
end
That gives the computer’s default “endian”, whether it’s ‘b’ on godzilla or ‘l’ on house.