MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

### Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

# I am having problem using hex2dec. It shows an error when it is used.

Asked by Suhas Holla on 24 Mar 2013

I am using MATLAB R2009. And I have problem using hex2dec. I am permutating a the row element after using dec2hex, and then using hex2dec. and it show the following error message.

Error using ==> hex2dec at 38
Input string found with characters other than 0-9, a-f, or A-F.
Error in ==> crypt_d at 62
td8=hex2dec(td8);

when i check the td8 variable the element which has zeros has been replaced by empty space as in

td8
td8 =
0C F 9

the space between C and F and F and 9 is supposed to be zeros. Can anyone please tell how to overcome these problem.

this is the part of the code where error is occurring

for i=1:si
td8=de_hex4(i,:);
td8=hex2dec(td8);
decr4=[decr4 ; td8-ad4];
end

## 1 Answer

Answer by the cyclist on 24 Mar 2013
Edited by the cyclist on 24 Mar 2013

I am not sure where you got the variable de_hex4, but if you are confident that all you need to do is replace the spaces with zeros, then you can do that with the regexprep function:

td8 = regexprep(td8,' ','0');

before you then send it to hex2dec.

## 2 Comments

Walter Roberson on 24 Mar 2013

I think de_hex4 is a variable, but I do not know what was assigned to it.

the cyclist on 24 Mar 2013

You are right. I wrote function instead of variable. I have edited.

Contact us