getting very weird number from hex2dec()
이전 댓글 표시
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!
채택된 답변
추가 답변 (1개)
William
2012년 1월 20일
0 개 추천
댓글 수: 1
Walter Roberson
2012년 1월 20일
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)
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!