필터 지우기
필터 지우기

Cell Array Indexing of HEX values

조회 수: 7 (최근 30일)
tinkyminky93
tinkyminky93 2022년 6월 2일
편집: Voss 2022년 6월 2일
Hello,
I have a HEX cell array and I use importdata function to import them.
a = importdata('C:\User\Desktop\text.txt');
It gives me 2x1 cell '0F 04 0A 0E 1E 2F' and '3E 2A 1F 03 05 0A'
For example, I want to take 0E from there, how can I index this element? Thank you.

채택된 답변

Voss
Voss 2022년 6월 2일
편집: Voss 2022년 6월 2일
a = {'0F 04 0A 0E 1E 2F', '3E 2A 1F 03 05 0A'};
C = squeeze(split(a,' '))
C = 2×6 cell array
{'0F'} {'04'} {'0A'} {'0E'} {'1E'} {'2F'} {'3E'} {'2A'} {'1F'} {'03'} {'05'} {'0A'}
C{1,4}
ans = '0E'
  댓글 수: 2
tinkyminky93
tinkyminky93 2022년 6월 2일
편집: tinkyminky93 2022년 6월 2일
Can we write like C(1, 4:5) or something like that for cell arrays?
Voss
Voss 2022년 6월 2일
편집: Voss 2022년 6월 2일
Try it and see:
a = {'0F 04 0A 0E 1E 2F', '3E 2A 1F 03 05 0A'};
C = squeeze(split(a,' '));
C(1, 4:5)
ans = 1×2 cell array
{'0E'} {'1E'}
Seems to work.
Note that subscripting a cell array with parentheses ( ) like that gives you another cell array. To get the contents of the cells instead, use braces { }:
C{1, 4:5}
ans = '0E'
ans = '1E'
And you may want to concatenate those 2 outputs together, using square brackets [ ]:
[C{1, 4:5}]
ans = '0E1E'
Another example:
[C{2,:}]
ans = '3E2A1F03050A'

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by