I am very new to matlab. I want to store hexadecimal values in array like this
P=[0x96,0x97,0x98];
But I surfed on google I got no solution for it So first I converted this hexadecimal into decimal so I got array like this
P=[150,151,152];
Now I am trying to get hexadecimal value of values of P array.
I tried
P=[dec2hex(150),dec2hex(151),dec2hex(152)];
But when I am trying to print P(1) then instead of 96 I got only 9. I am not understanding this part. How can I get correct result? Please help me.
Matlab stores hexadecimal number as character arrays (or strings).
So
a = dec2hex(150)
returns:
a = '96'
concatenating hexadecimal strings as you do:
P=[dec2hex(150),dec2hex(151),dec2hex(152)]
returns:
P = '969798'
Therefore, P(1) = '9'
You probably want to use cell arrays to separately store hex-numbers:
P = {dec2hex(150),dec2hex(151),dec2hex(152)};
P{1}
returns:
P = '96'
to retrieve the numeric value, use
hex2dec(P{1})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With