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 Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by