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 comentarios

Have you checked here?
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.

Iniciar sesión para comentar.

Respuestas (1)

Guillaume
Guillaume el 22 de Oct. de 2019
Editada: Guillaume el 22 de Oct. de 2019
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);

Categorías

Más información sobre Data Type Conversion en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 22 de Oct. de 2019

Editada:

el 22 de Oct. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by