3D-matrix
1 次查看(过去 30 天)
显示 更早的评论
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
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
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]);
0 个评论
更多回答(1 个)
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}
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!