MATLAB支持包罗有标记和无标记整数以及单精度和双精度浮点数的各类数字范例。 默认环境下，MATLAB将所有数值存储为双精度浮点数。

## 转换为各类数值数据范例

MATLAB提供以下函数来将数值转换为各类数字数据范例 -

`double` 转换为双精度数
`single` 转换为单精度数
`int8` 转换为`8`位有标记整数
`int16` 转换为`16`位有标记整数
`int32` 转换为`32`位有标记整数
`int64` 转换为`64`位有标记整数
`uint8` 转换为`8`位无标记整数
`uint16` 转换为`16`位无标记整数
`uint32` 转换为`32`位无标记整数
`uint64` 转换为`64`位无标记整数

``````x = single([5.32 3.47 6.28]) .* 7.5
x = double([5.32 3.47 6.28]) .* 7.5
x = int8([5.32 3.47 6.28]) .* 7.5
x = int16([5.32 3.47 6.28]) .* 7.5
x = int32([5.32 3.47 6.28]) .* 7.5
x = int64([5.32 3.47 6.28]) .* 7.5
``````

``````x =

39.900   26.025   47.100

x =

39.900   26.025   47.100

x =

38  23  45

x =

38  23  45

x =

38  23  45

x =

38  23  45
``````

``````x = int32([5.32 3.47 6.28]) .* 7.5
x = int64([5.32 3.47 6.28]) .* 7.5
x = num2cell(x)
``````

``````Trial>> x = int32([5.32 3.47 6.28]) .* 7.5
x = int64([5.32 3.47 6.28]) .* 7.5
x = num2cell(x)

x =

1×3 int32 行向量

38   23   45

x =

1×3 int64 行向量

38   23   45

x =

1×3 cell 数组

{[38]}    {[23]}    {[45]}
``````

## 最小和最大的整数

`intmax()``intmin()`函数返回可以用所有范例的整数暗示的最大值和最小值。

``````% displaying the smallest and largest signed integer data
str = 'The range for int8 is:\n\t%d to %d ';
sprintf(str, intmin('int8'), intmax('int8'))
str = 'The range for int16 is:\n\t%d to %d ';
sprintf(str, intmin('int16'), intmax('int16'))
str = 'The range for int32 is:\n\t%d to %d ';
sprintf(str, intmin('int32'), intmax('int32'))
str = 'The range for int64 is:\n\t%d to %d ';
sprintf(str, intmin('int64'), intmax('int64'))

% displaying the smallest and largest unsigned integer data
str = 'The range for uint8 is:\n\t%d to %d ';
sprintf(str, intmin('uint8'), intmax('uint8'))
str = 'The range for uint16 is:\n\t%d to %d ';
sprintf(str, intmin('uint16'), intmax('uint16'))
str = 'The range for uint32 is:\n\t%d to %d ';
sprintf(str, intmin('uint32'), intmax('uint32'))
str = 'The range for uint64 is:\n\t%d to %d ';
sprintf(str, intmin('uint64'), intmax('uint64'))
``````

``````ans =

'The range for int8 is:
-128 to 127 '

ans =

'The range for int16 is:
-32768 to 32767 '

ans =

'The range for int32 is:
-2147483648 to 2147483647 '

ans =

'The range for int64 is:
-9223372036854775808 to 9223372036854775807 '

ans =

'The range for uint8 is:
0 to 255 '

ans =

'The range for uint16 is:
0 to 65535 '

ans =

'The range for uint32 is:
0 to 4294967295 '

ans =

'The range for uint64 is:
0 to 1.844674e+19 '
``````

## 最小和最大的浮点数

`realmax()``realmin()`函数返回可以用浮点数暗示的最大值和最小值。

Matlab教程

2017-11-02

MATLAB支持包罗有标记和无标记整数以及单精度和双精度浮点数的各类数字范例。 默认环境下，MATLAB将所有数值存储为双精度浮点数。可以选择将任何