Trying to do the simplest thing ever. Write a number in QT in binary mode (unsigned 16) and read the file in matlab. I use Append mode since I will be adding numbers to the file in the future But can’t seem to do this right.
This is the QT code:
QFile f("C:\\temp.dat");
f.open(QIODevice::WriteOnly | QIODevice::Append)
QDataStream out(&f);
out<<quint16(270);
f.close();
And this is the Matlab code:
fid = fopen('C:\\temp.dat');
F_nums = fread(fid,1,'*uint16');
fclose(fid);
Seems very simple but it reads the numbers wrongly…
Thank you!
The problem is really simple: you are writing big-endian data (MSB comes first), but Matlab by default expects little endian data. The fix is simple: