MATLAB Answers

How to separate a string(1x1 cell) into a 1x4 cell

2 ビュー (過去 30 日間)
Akana Juliet
Akana Juliet 2021 年 6 月 18 日
コメント済み: Akana Juliet 2021 年 6 月 18 日
Hi everyone! I have a long string of 4 hex codes separated by spaces, (Example: 'A5E6C11D B5E6C11D C5E6C11D D5E6C11D') stored in one 1x1 cell (Or rather a 1x35 char type)
But I would like to separate each hexadecimal string into a 1x4 vector (or a 4x1 doesn't matter)
result = strjoin(HexCodes(fourElementIndex), ' ');
The above is the code I have that prints all 4 selected HexCodes into one cell. It's a little tricky because I am pulling the Hex codes from a cell of "HexCodes" by the fourElementIndex(1x4 double) which stores the 4 numbers that tell which hex codes to pull. Maybe there is a code that can follow this one that I have?
Any help would be greatly appreciated!

採用された回答

Stephen
Stephen 2021 年 6 月 18 日
chr = 'A5E6C11D B5E6C11D C5E6C11D D5E6C11D';
spl = split(chr)
spl = 4×1 cell array
{'A5E6C11D'} {'B5E6C11D'} {'C5E6C11D'} {'D5E6C11D'}
  1 件のコメント
Akana Juliet
Akana Juliet 2021 年 6 月 18 日
Fantastic! Stephen comes through yet again!

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

その他の回答 (1 件)

James Tursa
James Tursa 2021 年 6 月 18 日
If the hex codes are always 8 characters, why can't you just pick off the characters you want? E.g.,
{result(1:8),result(10:17),result(19:26),result(28:35)}
  1 件のコメント
Akana Juliet
Akana Juliet 2021 年 6 月 18 日
Thank you!

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

Community Treasure Hunt

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

Start Hunting!

Translated by