How to Split hexadecimal in to separate bytes?
15 views (last 30 days)
Show older comments
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
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.
Accepted Answer
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])
More Answers (0)
See Also
Categories
Find more on Data Import from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!