getting very weird number from hex2dec()
Show older comments
Hello,
I am attempting to convert large matrices of doubles to hex. I have an S matrix [2048 x 984] full of zeros
If I do this
>> dec2hex(s1a(1,3))
ans =
0
which is what should happen. However If I do this.....
HexS1a = ones(2048,984);
for aa = 1:984
for bb = 1:2048
HexS1a(bb,aa) = HexS1a(bb,aa)*dec2hex(s1a(bb,aa));
end
end
I get a matrix of "48"'s not zeros. The type is double. Can anyone explain this? It's driving me nuts!
Accepted Answer
More Answers (1)
William
on 20 Jan 2012
0 votes
1 Comment
Walter Roberson
on 20 Jan 2012
t = dec2hex(sla(1,3)) - '0';
t(t>9) = t(t>9) - 7;
However, if this is your aim, to get the numeric equivalent of each group of 4 bits, you can do that in other ways. For example,
HexPerVal = 2; %hex digits per sla entry
t2 = reshape(dec2bin(sla(:),HexPerVal*4).', 4, []).' - '0';
t3 = reshape(t2(:,1) * 8 + t2(:,2) * 4 + t2(:,3) * 2 + t2(:,4),2,[]).';
t4 = permute(reshape(t3,[HexPerVal,3,5]),[2 3 1]);
Now t4 would be an array whose first two dimensions were the same as sla's dimensions, and whose third dimension would be 1 to the number of hex digits per value (as determined by HexPerval)
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!