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.

 Akzeptierte Antwort

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

Weitere Antworten (0)

Produkte

Tags

Noch keine Tags eingegeben.

Community Treasure Hunt

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

Start Hunting!

Translated by