gpt4 book ai didi

matlab - Matlab中的cast()和typecast()命令有什么区别

转载 作者:太空宇宙 更新时间:2023-11-03 20:23:42 25 4
gpt4 key购买 nike

在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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com