3D-matrix
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Can an 3D matrix store the coordinates (x,y,z) for each value in the matrix. Something like,
M_coord = [ {1,1,1}, {1,2,1}, {1,3,1}; {2,1,1}, {2,2,1}, {2,3,1}; {3,1,1}, {3,2,1}, {3,3,1} ];
1 commentaire
Jan
le 15 Août 2011
@Susan: Please read this again: http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer , http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup , http://www.mathworks.com/matlabcentral/answers/728-how-do-i-write-a-good-question-for-matlab-answers.
Réponse acceptée
Jan
le 15 Août 2011
A "matrix" is 2D. In consequence a "3D matrix" cannot store anything.
As long, as you do not specify exactly, what you want, it is impossible to give a valuable answer. But of course I can guess, that you want a CELL matrix:
M_coord = {[1,1,1], [1,2,1], [1,3,1]; ...
[2,1,1], [2,2,1], [2,3,1]; ...
[3,1,1], [3,2,1], [3,3,1]}
Or perhaps a 3D array:
M_coord = cat(3, [1,1,1; 2,1,1; 3,1,1], ...
[1,2,1; 2,2,1; 3,2,1], ...
[1,3,1; 2,3,1; 3,3,1]);
0 commentaires
Plus de réponses (1)
Walter Roberson
le 15 Août 2011
There are disagreements in terminology as to what a "matrix" is. My background is sufficiently different than Jan's that I have no problem talking about a "3D Matrix".
Here is a generalization for larger sizes. Let M, N, and P be the dimensions you want:
[mg, ng, pg] = ndgrid(1:M, 1:N, 1:P);
M_coord = arrayfun(@(m,n,p) {[m,n,p]}, mg, ng, pg);
Then, e.g., M_coord{2,1,4}
0 commentaires
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices 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!