"_my BinaryMat consists of 48s and 49s instead of 1s and 0s."_
I didn't try to read the code but somewhere you've converted the char return to its internal representation. '48' is the decimal value of the character '0'
>> double('0')
ans =
48
>> char([48;49])
ans =
2×1 char array
'0'
'1'
>>
>> dec2bin(hex2dec('F'))
ans =
'1111'
>> double(ans)
ans =
49 49 49 49
>>
ADDENDUM
I think you can get to useful result quite a lot more simply...see if the following won't serve for your purposes:
function bin=hexmat2bin(HexMat)
[m,n]=size(HexMat);
HexC=mat2cell(HexMat,ones(1,m),ones(1,n));
bin=reshape(cellstr(dec2bin(hex2dec(HexC),4)),m,[]);
end
For your sample input (which I used as the help file example as well) one gets
>> BinaryMat=hexmat2bin(HexMat)
BinaryMat =
3×3 cell array
{'0001'} {'0010'} {'0000'}
{'1010'} {'1100'} {'1000'}
{'1001'} {'0110'} {'1111'}
>>
All you need to do is to dereference the cell array to retrieve any given character string desired--remember that's using the "curlies" instead of ordinary parentheses:
>> BinaryMat{1,2}
ans =
'0010'
>>
Best Answer