Convert hexadecimal cell information to struct

4 visualizzazioni (ultimi 30 giorni)
Bram Surewaard
Bram Surewaard il 11 Ago 2020
Modificato: Bram Surewaard il 28 Ago 2020
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
  4 Commenti
Bram Surewaard
Bram Surewaard il 13 Ago 2020
I think that it comes done to this:
I am able to get the data that I need with the following command:
Data{1,1}(1,34:37)
Which gives me:
1×4 cell array
{'02'} {'a5'} {'7b'} {'31'}
Now I need to stitch these numbers togeter into one number that i can convert with hex2dec.
However I am not able to find a way of getting this done and I dont know the right terminology to find it.
Does anybody know how I can achieve this?

Accedi per commentare.

Risposte (1)

David Hill
David Hill il 13 Ago 2020
hex2dec(cell2mat(a));
  2 Commenti
Bram Surewaard
Bram Surewaard il 28 Ago 2020
This does stitch the number together, however the outcome is not the desired characters it is not just a large number, any idea how I can still convert this to a string of characters?
Bram Surewaard
Bram Surewaard il 28 Ago 2020
Found it, I can use convertCharsToStrings() to stitch the 4x1 char into one string

Accedi per commentare.

Categorie

Scopri di più su Data Type Conversion in Help Center e File Exchange

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by