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.

 採用された回答

MathWorks Support Team
MathWorks Support Team 2009 年 6 月 27 日

0 投票

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 件)

カテゴリ

製品

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by