get p*(q*m) matrix from m*n matrix and p*q indexing matrix
조회 수: 1 (최근 30일)
이전 댓글 표시
hey everyone,
is there an elegant way to get the following:
C=rand(8,n) %given
index=[...
1 5 1 2 3 4
2 6 2 3 4 1
3 7 6 7 8 5
4 8 5 6 7 8
1 5 1 2 3 4];
X=[...
C(1,1) C(5,1) C(1,1) ... ... C(4,1) C(1,n) C(5,n) C(1,n) ... ... C(4,n)
C(2,1) C(6,1) C(2,1) ... ... C(1,1) C(2,n) C(6,n) C(2,n) ... ... C(1,n)
C(3,1) C(7,1) C(6,1) ... ... C(5,1) ... C(3,n) C(7,n) C(6,n) ... ... C(5,n)
C(4,1) C(8,1) C(5,1) ... ... C(8,1) C(4,n) C(8,n) C(5,n) ... ... C(8,n)
C(1,1) C(5,1) C(1,1) ... ... C(4,1) C(1,n) C(5,n) C(1,n) ... ... C(4,n)
]
X=C(index,:)
gives the information but not arranged as desired. it is for plotting cubes by edge coordinates in 3d with patch command.
thanks for any help!
댓글 수: 0
채택된 답변
Davide Masiello
2022년 10월 17일
편집: Davide Masiello
2022년 10월 17일
Something like this?
n = 3;
C = rand(8,n)
index=[...
1 5 1 2 3 4
2 6 2 3 4 1
3 7 6 7 8 5
4 8 5 6 7 8
1 5 1 2 3 4];
X = reshape(C(index(:),1:n),size(index,1),size(index,2)*n)
댓글 수: 2
Davide Masiello
2022년 10월 17일
I understand, I have changed my answer.
I believe it should work that way either.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!