What is best option to separate bytes from hex vector (char vector)?

Hi, I have a HEX vector:
A = 'ABCDEF12';
and I want to seprate them to array or cell by bytes:
{"AB"},{"CD"},{"EF"},{"12"}
I know that this is easy, but i have no idea. Best option would be loop here

3 Comments

Do you want the split results to remain as char or string, or will they be converted to numeric values for downstream use?
Comment by Phill Lord probably as an answer to kalyan's comment originally posted as an answer moved here:
Thanks, I have checked, but this not helped me :( In that solution, we have a known character to split - I need split every double chars.

Sign in to comment.

Answers (1)

Assuming that the number of characters is even:
split = mat2cell(A, 1, repelem(2, numel(A)/2))
Note that this will produce a cell array of char vectors. You show your desired output as a cell array of scalar strings ("" notation instead of '' notation). It wouldn't make sense to generate a cell array of strings, you'd either have a cell array of char vectors as the above or a plain string array, which you'd obtain from the above with:
s_split = string(split);

Categories

Asked:

on 22 Oct 2019

Edited:

on 22 Oct 2019

Community Treasure Hunt

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

Start Hunting!