Hello
I have an array of hex numbers which I want to convert to decimal. These is an array converted from a table.
For eg.var = readtable()
var = table2array(var)
Now when I try to use hex2dec on this var it does not work. It gives the error message:
"Error using hex2dec
Hexadecimal text must consist of characters 0-9 and A-F."
When I put a quotation for each individual number inside the var, I can get it to work. But since this is an array with thousands of numbers, I cannot do it this way. I need to use hex2dec(var(:,1)) on the entire array. is there any way I can do it ?

댓글 수: 5

Stephen23
Stephen23 2022년 10월 4일
" is there any way I can do it ?"
Most likely yes, but you don't provide enough details or an actual data file for us to work with. Most likely TABLE2ARRAY is a red herring and does not help. These might help:
  • any single variable/column of the table, e.g. hex2dec(var{:,1})
  • importing/converting as a cell array.
  • importing the text as string.
  • using a suitable function to iterate over the rows/elements of the table.
Walter Roberson
Walter Roberson 2022년 10월 4일
편집: Walter Roberson 2022년 10월 4일
After the table2array what shows up for class(var) and size(var) and unique(var(:)) ?
Shrinish Donde
Shrinish Donde 2022년 10월 4일
class(var) = 'string'
size(var) = 18819 2
unique(var) = 18819x2 string
David Hill
David Hill 2022년 10월 4일
Attach your data.
cs = cellstr(var);
ca = vertcat(cs{:});
u = unique(ca(:))
Look carefully at the output of u for any characters other than A B C D E F a b c d e f 0 1 2 3 4 5 6 7 8 9 . In particular look for space in the output. hex2dec() can handle leading and trailing spaces, but not embedded spaces.
For example if one of the strings as DE AD BE EF then hex2dec() would not be able to handle the space.
If you have an array with embedded spaces, then do you want each element to become an output value, or should the elements be grouped together? For example you might want to group BE EF together to get hex BEEF (a 16 bit integer) ?

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Tables에 대해 자세히 알아보기

제품

릴리스

R2020a

질문:

2022년 10월 4일

댓글:

2022년 10월 5일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by