MATLAB: Does FREAD read the data incorrectly when using the ‘char’ format specification with MATLAB 7.3 (R2006b) on Linux

charfreadlinuxMATLABskipunix

When I use the following command on Windows with MATLAB 7.3 (R2006b):
a=fread(fopen('test'),64,'char')';
size(a)
I obtain
ans =
1 64
On Linux I obtain:
ans =
1 62
'schar' and 'uchar' format specification give me the same answer with FREAD on every platforms.

Best Answer

'char' to FREAD means "read a character in the local codepage". The local codepage is different on Windows and Linux, so that is why there are different results between OSes. To read unsigned bytes and not characters, the correct precision specification is 'uint8' (which is the same as 'uchar').