How to Split hexadecimal in to separate bytes?

15 vues (au cours des 30 derniers jours)
vinvino
vinvino le 25 Juil 2018
Commenté : vinvino le 27 Juil 2018
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 commentaire
Guillaume
Guillaume le 26 Juil 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.

Connectez-vous pour commenter.

Réponse acceptée

Guillaume
Guillaume le 26 Juil 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 commentaire
vinvino
vinvino le 27 Juil 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])

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Data Import from MATLAB dans Help Center et File Exchange

Produits


Version

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by