I was thinking that since the code has some error checking at the top, it should probably also take account of the situation where the file can't be opened. If that's the case at the moment (say the file isn't there) the line:
fh = fopen(fname, 'rt');
returns -1 into fh. That could be checked and acted on below that, for example like this:
[fh, fMsg] = fopen(fname, 'rt');
if ( fh == -1 )
disp(['Error opening file: ' fMsg]);
return;
end
Otherwise, an error is thrown when the fread line is executed, and it goes to close the file on the fclose line just below it. Since it's not open, this throws another error and the code exits with an error before the rethrow line is executed.