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

标签 matlab casting

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

相关文章:

matlab - 如何在 MATLAB 中将 3 列矩阵绘制为彩色图?

matlab - 在 Octave 中绘制峰值函数无法生成正确的图表

matlab - 根据特定子表达式重写符号表达式

c++ - 了解 C++ 中的转换

c++ - boost::任何带有 char[] 的 map

sql-server - 是否存在一种方法来验证像 'Abr 21 2010 12:00AM' 这样的字符串是日期时间还是转换为日期时间之后?

Python 或 matlab。需要根据一组坐标计算曲率

matlab - 开源 Matlab 打包工具

arrays - Swift - 如何将 Any 转换为 Array\Dictionary?

c - 为什么 linux 内核使用双重逻辑否定而不是强制转换为 bool 值?