我有一个Matlab脚本调用一个C代码来读取我的dat文件,该文件由我的所有数据组成,其中一个是timestamp_low。在Windows上运行我的脚本我得到正确的时间值4.1472 * 10 ^ 9但是linux / mac我得到值1.8447 * 10 ^ 19。基本上我只是从文件中读取并保存它。
unsigned int timestamp_low = inBytes[0] + (inBytes[1] << 8) +
(inBytes[2] << 16) + (inBytes[3] << 24);
mxSetField(outCell, 0, "timestamp_low", mxCreateDoubleScalar((double)timestamp_low));
有没有人知道mex-compiler在不同操作系统上的工作方式是否有所不同?我自己没有写过这段代码,所以我不太熟悉细节。我用它从WiFi设备收集CSI。我尝试过不同的Matlab版本和Mac / Linux,它们产生相同(错误)的值。
答案 0 :(得分:1)
我怀疑你在这里有一些未定义的行为:
unsigned int timestamp_low = inBytes[0] + (inBytes[1] << 8) +
(inBytes[2] << 16) + (inBytes[3] << 24);
(虽然不清楚,因为你没有告诉我们inBytes
的类型。
尝试:
unsigned int timestamp_low = (unsigned int)inBytes[0] + ((unsigned int)inBytes[1] << 8) +
((unsigned int)inBytes[2] << 16) + ((unsigned int)inBytes[3] << 24);