MATLAB Answers

How to Split hexadecimal in to separate bytes?

39 ビュー (過去 30 日間)
vinvino
vinvino 2018 年 7 月 25 日
コメント済み: vinvino 2018 年 7 月 27 日
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 件のコメント
Guillaume
Guillaume 2018 年 7 月 26 日
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.

サインインしてコメントする。

採用された回答

Guillaume
Guillaume 2018 年 7 月 26 日
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 件のコメント
vinvino
vinvino 2018 年 7 月 27 日
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 件)

製品


リリース

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by