Reputation: 321
Let's say i have a 1x32 double array Input in matlab workspace. This variable has all positive decimal values. I want to convert each value to Hex & store it in another array Output
I use dec2hex(Input) & it generates a character string with Hex values. Now, i want an array of Hex numbers & not a string.
How do i convert this Hex string into Hex array of 1x32 Output
If i use str2num or str2double, it gives empty & NaN respectively?
How to do it
Upvotes: 2
Views: 7482
Reputation: 7751
Matlab does not manage hexadecimal numbers per se, only decimal notation. That's why matlab stores hexadecimal numbers in string format.
To do an addition of hex for example, you have to pass through the decimal notation:
a='ABC';
b='123';
c=dec2hex(hex2dec(a)+hex2dec(b))
Upvotes: 1
Reputation: 6424
to get neither empty nor Nan values use `hex2dec'. something like this works for me:
a=1:20;
b=dec2hex(a);
c=hex2dec(b)
ans =
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Upvotes: 5