在matlab工作区中执行这些命令
a = 10
b = cast(a,'uint8')
c = typecast(a,'uint8')
当我寻找 b 和 c 的值时,我得到了
b = 10
c = 0 0 0 0 0 0 36 64
whos('b')
和 whos('c')
也返回 uint8
最佳答案
答案来自documentation of typecast
:
typecast is different from the MATLAB® cast function in that it does not alter the input data. typecast always returns the same number of bytes in the output Y as were in the input X. For example, casting the 16-bit integer 1000 to uint8 with typecast returns the full 16 bits in two 8-bit segments (3 and 232) thus keeping its original value (3*256 + 232 = 1000). The cast function, on the other hand, truncates the input value to 255.
关于matlab - Matlab中的cast()和typecast()命令有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39990908/