MATLAB: Declare contents of string variable as an explicit type without formatting them

convertstring

Good day,
I try to convert a .hex file to a desired format using Matlab.
Up to now, i have managed to read the file and store its components to a cell string array ( Nx1 size, with N being the lines of the original file )
Now, what i try to do is read each element of the above mentioned cell array and break it into meaningful parts ( number of data bytes included in the line, target address, checksum etc … ).
All these info are already included in each of the elements, so it is a matter of reading the correct characters to do that.
My question: At some point, i will need to do some manipulation of the data ( specifically, divide the address [ in hex format ] by 2 ).
How can i make Matlab understand that the specific string variable ( let's say 'Address' for the sake of argument ) includes data that is originally in hex format, and should be treated as such?

Best Answer

What do you think is "hex format"?
Do you have a F8 and want to get the half of it?
hex = 'F8';
dec = sscanf(h, '%x');
half = dec / 2;
Do not try to calculate with hex values. Convert them to doubles or integers, than the processing gets trivial.