functions to combine two hexadecimal numbers

I'm doing a project that involves taking in data from an EMG, running it through a function in Matlab, and sending commands to a series of motors. The motors take a series of 2 hex numbers, one 2 digits, one 4 digits preceded by the letter d. For example, d0103FF. My question is, how can I write a series of functions that takes the difference between two numbers, converts it to a zero padded four digit hexadecimal, and then tacks it onto the end of dXX where X is another number.

댓글 수: 2

Chaowei Chen
Chaowei Chen 2011년 9월 25일
can you give an example about the I/O? If the format is regular, my approach would be to treat d0103FF as a string and read it digit by digit
Peter
Peter 2011년 9월 25일
An EMG signal is going to be processed and classified as a number. This number determines which set of functions to use. The output is d followed by a zero-padded 2 digit hex number followed by a zero padded 4 digit hex number. In order to determine the four digit number,the current motor rotation is subtracted from the desired rotation. This number is turned into hex with dec2hex. I need to figure out how to take the number calculated and insert it after the d and two hex digits.

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

 채택된 답변

Rick Rosson
Rick Rosson 2011년 9월 25일

0 개 추천

y = desired - actual;
h2 = dec2hex(x,2);
h4 = dec2hex(y,4);
out = [ 'd' h2 h4 ];

추가 답변 (2개)

Jan
Jan 2011년 9월 25일

0 개 추천

SPRINTF('%x') and the corresponding FPRINTF commands are very fast for the conversion of hexadecimal and decimal numbers - mucgh faster than HEX2DEC and DEC2HEX:
out = sprintf('d%.2x%.4x', x, y)

카테고리

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

질문:

2011년 9월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by