matlab - Performance issue strcat and hex2dec -


the dec2hex(d) function in matlab returns 2-d string array each row hexadecimal representation of each decimal integer in d. suppose use function read input data (ansi characters), , convert data 1-byte hexadecimal representations, such resulting matrix l x 4 char matrix (should l x 2 still). since there 2-byte numbers present in data cannot convert these hex values decimal values. now, decimal value of these 2 byte hex numbers, use following line (the later value in matrix corresponds msb):

hex2dec(strcat(data_hex(index+1,:),data_hex(index,:))); 

so concatenate 2 rows of hex matrix (each containing 4 columns single chars), single string, , transform string decimal. however, takes lot of time; line executed 7000 times , takes 1.2 seconds. since still relatively small data set, i'm looking faster way achieve goal. note converting whole hex matrix decimal numbers takes negligible amount of time, hoping use decimal representations instead. appreciated!

example reading 2-byte hexadecimal number:
- create vector consisting of 2 decimal values (e.g. t = [46 23])
- convert vector hexadecimal representation: t_hex = dec2hex(t). resulting matrix sized 2x2 , each element char (for example t_hex=[2e;17]
- want read matrix single value "172e", , convert decimal number. used line above, in case hex2dec(strcat(t_hex(2,:),t_hex(1,:))), has 5934 output

try running hex2dec separately on each of bytes. can combine lsb , msb arrays using results = 256*msb + lsb

you can try using sscanf(hexstr,'%x') rather hex2dec(hexstr). on system sscanf 3-4 faster.


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -