Four indexing matrix
조회 수: 6 (최근 30일)
이전 댓글 표시
I have a matrix nxn, each element is described by a 2 index number (i.e. one number for the column, one for the row). The problem is that i want to access this matrix by a four digit indexing. Is there a way to do that?
댓글 수: 3
Jan
2011년 7월 22일
There is an infinite number of possibilities to map "A(k,l,m,n)->p(i,j)". Please specify how {k,l,m,n} and {i,j} are connected.
채택된 답변
추가 답변 (2개)
Friedrich
2011년 7월 21일
Hi,
I am not sure what you mean with 4digit indexing. Do you want a 4d matrix?
>> a = zeros(3,3,3,3);
>> a(1,2,1,3)
ans =
0
Or do you like to pass 2 pairs of indices?
a = [1 2; 3 4]
%try to access 1,1 and 1,2
ind = sub2ind(size(a),[1 1],[1 2])
a(ind)
ans =
1 2
Jan
2011년 7월 22일
One example:
A = rand(3, 4, 5, 6);
p = reshape(A, 12, 30);
disp(A(2,3,4,5))
disp(p(8, 24))
Does this match your needs? Then SUB2IND and IND2SUB might help.
참고 항목
카테고리
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!