Convert hexadecimal cell information to struct
2 ビュー (過去 30 日間)
古いコメントを表示
Hey,
So i have this Data that is a 8306x1 cell filled with 1x1872 cells, and each cell from this is filled with hexidecimal input. I have atteched the first 10 inputs of the Data file.
What I need to do is to get the hexidecimal input from certain cells and convert those to either char or normal values. This is where I am stuck as I have no idea how to achieve this. I tried using:
char(hex2dec(Data{1,1}(1,9:12)))
However then I get this:
4×1 char array
'B'
'T'
'H'
'0'
And I need to have this into one char and not in this array form, and same goes for converting hexidecimal numbers into normal numbers for different amount of hexidecimal values.
I hope I have explained the problem well and anybody is able to help me.
Thanks!
Edit:
Oke so this would be the input starting from Data{1,1}{1,137} until Data{1,1}{1,156}
'52' '30' '02' '08' '36' '80' '80' '80' '02' 'ba' '02' 'ba' '02' 'ba' '02' 'ba' '02' 'bb' '02' 'bb'
And I would like to save it into a struct like this:
Frame.SectionName = R0 (short) , (so the first two cells of the input above ['52' '30'] )
Frame.SectionSize = 520 (short), (input 139 and 140 ['02' '08] )
Frame.ScalingFactor = 0.00000382965663 (floating point number) , (input 141 till 144, ['36' '80' '80' '80'] )
Frame.Range = [ 698 698 698 698 699 699] so this needs to be able to save all the range measurements from many inputs, (input 145 till 156, ['02' 'ba' '02' 'ba' '02' 'ba' '02' 'ba' '02' 'bb' '02' 'bb'] )
I hope this is a bit clear, I got these names from a pdf file describing the data format which looks like this:
u16 R0_SectionName; // 'R0'
u16 R0_SectionSize; // [bytes] size of this entire section
f32 R0_ScalingFactor;
u16 R0_Range[H0_Points]; // [seconds two-way] = R0_Range * R0_ScalingFactor
With the type defenitions being:
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
typedef signed char s8;
typedef signed short s16;
typedef signed int s32;
typedef float f32;
typedef float f64;
UPDATE:
I managed to get it working for characters, however i cant seem to make it work for normal numbers.
For instance i have now a 1x4 cell array with 00 00 07 48 which i need to find a way to get it into one single number so that i can converti the hex (00000748) to the desired 1864
found it, it can be done with cell2mat
回答 (1 件)
参考
カテゴリ
Help Center および File Exchange で Cell Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!