Retrieving indexing of a cell
조회 수: 2 (최근 30일)
이전 댓글 표시
I have the variable NameMatrix < nx5 cell > where the number of columns(5) always stays the same and the number of rows(n) changes.
For n=4, NameMatrix looks like this:
'A1' 'A2' 'A3' 'A4' 'A5'
'B1' 'B2' 'B3' 'B4' 'B5'
'C1' 'C2' 'C3' 'C4' 'C5'
'D1' 'D2' 'D3' 'D4' 'D5'
For n=11, NameMatrix looks like this:
'A1' 'A2' 'A3' 'A4' 'A5'
'B1' 'B2' 'B3' 'B4' 'B5'
'C1' 'C2' 'C3' 'C4' 'C5'
'D1' 'D2' 'D3' 'D4' 'D5'
'E1' 'E2' 'E3' 'E4' 'E5'
'F1' 'F2' 'F3' 'F4' 'F5'
'G1' 'G2' 'G3' 'G4' 'G5'
'H1' 'H2' 'H3' 'H4' 'H5'
'I1' 'I2' 'I3' 'I4' 'I5'
'J1' 'J2' 'J3' 'J4' 'J5'
'K1' 'K2' 'K3' 'K4' 'K5'
I do some operations with NameMatrix and as a result for the case where n=11, the new matrix looks like this
'F1'
'F2'
'F3'
'F4'
'F5'
'G1'
'G2'
'G3'
'G4'
'G5'
'H1'
'H2'
'H3'
'H4'
'H5'
'I1'
'I2'
'I3'
'I4'
'I5'
'J1'
'J2'
'J3'
'J4'
'J5'
'K1'
'K2'
'K3'
'K4'
'K5'
'A1'
'A2'
'A3'
'A4'
'A5'
'B1'
'B2'
'B3'
'B4'
'B5'
'C1'
'C2'
'C3'
'C4'
'C5'
'D1'
'D2'
'D3'
'D4'
'D5'
'E1'
'E2'
'E3'
'E4'
'E5'
I would like to extract the indices of this new matrix. So F1 = 26, F2 =27, F3=28, F4=29, F5=30, G1=31, G2=32, G3=33, etc. SO i get a new vector which looks like this [26 27 28 29 30 31 32 33....] for an arbitrary number of rows n. Which would be the best way to do this?
댓글 수: 0
채택된 답변
Guillaume
2015년 6월 29일
Note that linear indices in matlab are per column rather than per row (so the indices of 'F1', 'F2', F3', etc. would be [6, 17, 28, ...]. If you do want [26, 27, ...] you'll have to transpose your initial matrix:
c = {'A1' 'A2' 'A3' 'A4' 'A5'
'B1' 'B2' 'B3' 'B4' 'B5'
'C1' 'C2' 'C3' 'C4' 'C5'
'D1' 'D2' 'D3' 'D4' 'D5'
'E1' 'E2' 'E3' 'E4' 'E5'
'F1' 'F2' 'F3' 'F4' 'F5'
'G1' 'G2' 'G3' 'G4' 'G5'
'H1' 'H2' 'H3' 'H4' 'H5'
'I1' 'I2' 'I3' 'I4' 'I5'
'J1' 'J2' 'J3' 'J4' 'J5'
'K1' 'K2' 'K3' 'K4' 'K5'};
cc = {'F1' 'F2' 'F3' 'F4' 'F5' 'G1' 'G2' 'G3' 'G4' 'G5' 'H1' 'H2' 'H3' 'H4'}';
[~, indices] = ismember(cc, c) %transpose c to get [26 27 ...]
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!