I am trying to extract numerical values from hexadecimal values which are generated and stored in the form of .csv data files. However, the format of these .csv data files was recently altered by an update, such that the code no longer works as it relies on the detection of a keyword, in this case 'CUSTOM_MODE_STEP', in order to pick out the relevant lines in the data file. For context, the original data format is thus:
CUSTOM_MODE_STEP_0 = { 0x40 0x43 0x7D 0xAF 0x96 0xA2 0x00 0x00 }
CUSTOM_MODE_STEP_1 = { 0x00 0xF4 0x7D 0xAF 0x96 0xA2 0x01 0x00 }
CUSTOM_MODE_STEP_2 = { 0x7C 0x00 0x7D 0xAF 0x96 0xA2 0x02 0x80 }
However, the format was changed, so that the hexadecimal-containing lines in the data files are now separated by strings of text which obviously cannot be read:
CUSTOM_MODE_STEP_0 = { 0x40 0x43 0x7D 0xA2 0xA2 0xA2 0x00 0x00 }
CUSTOM_MODE_STEP_0_DESCRIPTION = [text]
CUSTOM_MODE_STEP_1 = { 0x00 0xF4 0x7D 0xA2 0xA2 0xA2 0x01 0x00 }
CUSTOM_MODE_STEP_1_DESCRIPTION = [text]
CUSTOM_MODE_STEP_2 = { 0x7C 0x00 0x7D 0xA2 0xA2 0xA2 0x02 0x80 }
CUSTOM_MODE_STEP_2_DESCRIPTION = [text]
I am using a pre-written script, and I am trying to edit it so that it can accommodate this change. The script is below:
for f=fields'
if contains(f,'CUSTOM_MODE_STEP')
ht = DataN.Periph.(char(f));
list = strsplit(ht,{',', '{', '}'});
DataN.ht_1 = [DataN.ht_1; hex2dec(list{1,4}(4:end))*2];
DataN.ht_2 = [DataN.ht_2; hex2dec(list{1,5}(4:end))*2];
DataN.ht_3 = [DataN.ht_3; hex2dec(list{1,6}(4:end))*2];
DataN.ht_4 = [DataN.ht_4; hex2dec(list{1,7}(4:end))*2];
DataN.t_1 = [DataN.t_1; hex2dec(list{1,2}(4:end))];
DataN.t_2 = [DataN.t_2; hex2dec(list{1,3}(4:end))];
end
end
The variable 'fields' is a 27x1 array, of which the CUSTOM_MODE_STEP variables (both hexadecimal and text values) are present within.
I was thinking of inserting an elseif statement like:
elseif contains(f,'DESCRIPTION')
but I'm unsure as to what command to use exactly to exclude those lines. I've also thought about referencing the correct cells in that array using fields{} but that hasn't worked:
f=fields{17),fields{19},fields{21};
Those numbers being the coordinates for the hexadecimal lines.
Any further information needed please let me know.