How to Split hexadecimal in to separate bytes?

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 个评论

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.

请先登录,再进行评论。

 采纳的回答

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 个评论

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])

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Data Import from MATLAB 的更多信息

产品

版本

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by