Four indexing matrix
Mostra commenti meno recenti
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 Commenti
Oleg Komarov
il 21 Lug 2011
What do you mean? You want to retrieve two points at the same time?
Nikolaos
il 22 Lug 2011
Jan
il 22 Lug 2011
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.
Risposta accettata
Più risposte (2)
Friedrich
il 21 Lug 2011
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
1 Commento
Nikolaos
il 22 Lug 2011
Jan
il 22 Lug 2011
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.
5 Commenti
Nikolaos
il 22 Lug 2011
Andrei Bobrov
il 22 Lug 2011
pall=[1 2 3 4;5 6 7 8; 9 10 11 12; 13 14 15 16]
a = zeros(2,2,2,2)
a(:) = pall
Jan
il 22 Lug 2011
a = reshape(pall, 2,2,2,2);
Nikolaos
il 22 Lug 2011
Nikolaos
il 5 Ott 2011
Categorie
Scopri di più su Matrix Indexing in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!