Why do I receive an error when using the DEC2HEX function in MATLAB?

If I run the following code:
a = 12.0001;
b = dec2hex(a);
I receive the following error message:
??? Error using ==> dec2hex at 27
First argument must contain non-negative integers.

 采纳的回答

The DEC2HEX function throws this error if the input arguments are floating point numbers and not integers as expected.
A workaround for this issue would be to use the FIX command to make sure that the number being passed to DEC2HEX is an integer. For example:
dec2hex(fix(arg))
This may also be achieved by type-casting the number appropriately before passing it to DEC2HEX. For example:
dec2hex(int32(temp))

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Logical 的更多信息

产品

标签

尚未输入任何标签。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by