3D-matrix

1 次查看(过去 30 天)
Lizan
Lizan 2011-8-15
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 个评论
Jan
Jan 2011-8-15
@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.

请先登录,再进行评论。

采纳的回答

Jan
Jan 2011-8-15
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]);

更多回答(1 个)

Walter Roberson
Walter Roberson 2011-8-15
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}

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by