How to Split hexadecimal in to separate bytes?

15 views (last 30 days)
Hi i am having an array of Hex values like below, byte size may vary some times. I would like to split the byte by byte and place it in an array, is there any command? or how can i do it? Thanks in advance
HexVal =
0000
FFFF
0000
55FF
80FF
40FF
2BFF
expected OutPut is shown below (array)
00 00
FF FF
00 00
55 FF
80 FF
40 FF
2B FF
  1 Comment
Guillaume
Guillaume on 26 Jul 2018
What class is the expected output supposed to be? In any recent version of matlab, matlab will never display a variable exactly as shown, regardless of its type, unless the display function is overriden for that particular type.

Sign in to comment.

Accepted Answer

Guillaume
Guillaume on 26 Jul 2018
You haven't shown us the class of HexVal. From the error you get with Paolo's answer I suspect that HexVal is an Nx4 char array.
You could split it into a Nx2 cell array of 1x2 char vectors. It's trivial to do and also pointless and more likely will make the rest of the code more complicated. It's much simpler to use indexing to get whichever characters you want. It's simple column indexing. e.g. to get the first two characters of each row:
HexVal(:, [1 2])
and
HexVal(:, [3 4])
for the other 2.
If you do really want to physically split the columns (again, it's pointless):
mat2cell(HexVal, ones(size(HexVal, 1), 1), [2 2])
  1 Comment
vinvino
vinvino on 27 Jul 2018
Thank you Guillaume!! I used below command for my code and it is working. according to the byte size i want i adjust the range here [2 2].
mat2cell(HexVal, ones(size(HexVal, 1), 1), [2 2])

Sign in to comment.

More Answers (0)

Categories

Find more on Data Import from MATLAB in Help Center and File Exchange

Products


Release

R2016b

Community Treasure Hunt

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

Start Hunting!