Four Indexing of a two index matrix
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hallo, my problem is that i want to address each element of a matrix (2index) by a 4index number and vice versa.
for example, a typicall matlab matrix "A" has the 2 index addressing
11 12 13 14
21 22 23 24
31 32 33 34
41 42 43 44
I want to make matrix "A" to have four index addressing ie
1111 1112 1121 1122
1211 1212 1221 1222
2111 2112 2121 2122
2211 2212 2221 2222
... So instead of writting A(1,1) i would instead writte A(1,1,1,1) (The reshape command doesnt give me right results for the 36x36 matrices i use, i believe that it reshapes the matrix not the way of the example)
Thank you all in advance.
0 commentaires
Réponse acceptée
Walter Roberson
le 24 Nov 2011
Doing that and being consistent with the rest of MATLAB would require that you write a new MATLAB Object class with its own subsref() and subsasgn() methods, and possibly reshape() as well. You are asking that data be stored in a different order than MATLAB normally stores it. All kinds of routines (such as sum() and mean()) expect data to be stored in the MATLAB order.
However, it is possible that for your intended use, you just need to know how to re-order a vector with (36 * 36) elements so that it fills memory in to a 4D array with your desired order. If so, that can be done with transpose() and flipud() and fliplr() and permute() and reshape() in combination. You might not need all of those in practice for this particular order. (I haven't yet worked out a good reordering sequence for this.)
Plus de réponses (1)
Jan
le 24 Nov 2011
A = [1111 1112 1121 1122;
1211 1212 1221 1222;
2111 2112 2121 2122;
2211 2212 2221 2222];
B = reshape(A, 2,2,2,2);
C = permute(B, [2,1,4,3]);
>> ans(:,:,1,1) =
1111 1211
2111 2211
ans(:,:,2,1) =
1121 1221
2121 2221
ans(:,:,1,2) =
1112 1212
2112 2212
ans(:,:,2,2) =
1122 1222
2122 2222
Now the i.th index is equivalent to the i.th digit in the number. This works for the 4x4 matrix only and I cannot predict, what you need for your 36x36 matrix. But the method will be very similar.
Voir également
Catégories
En savoir plus sur Matrices and Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!