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