필터 지우기
필터 지우기

Separate the digits in a hex number

조회 수: 1 (최근 30일)
fiona rozario
fiona rozario 2017년 2월 18일
댓글: fiona rozario 2017년 2월 19일
I want to use the digits from hex numbers as indices to a lookup table. Eg: if the number is A9, A corresponds to the row of the lookup table and 9 corresponds to the column, so that I can pick up the value of the cell at the intersection of this row and column.
How can I separate 'A' and '9' in hex?

채택된 답변

Walter Roberson
Walter Roberson 2017년 2월 18일
>> sscanf('A9', '%1x')
ans =
10
9
  댓글 수: 3
Walter Roberson
Walter Roberson 2017년 2월 19일
rc = sscanf('A9', '%1x');
r = rc(1);
c = rc(2);
fiona rozario
fiona rozario 2017년 2월 19일
Thank you, so much!

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

추가 답변 (1개)

John D'Errico
John D'Errico 2017년 2월 18일
편집: John D'Errico 2017년 2월 18일
If you want the digits as an index into a table, then since indexing is 1-based in MATLAB, you want 'A' to map to 11, '9' maps to 10, '0' to 1, etc.
This will do:
H = 'F5A9';
[~,ind] = ismember(H,'0123456789ABCDEF')
ind =
16 6 11 10

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by