how do I create a matrix of array?

5 次查看(过去 30 天)
Carlo Alessi
Carlo Alessi 2017-2-19
回答: Matt J 2017-2-19
I want to create a matrix of data points like this
[0,0] [0,1] [0,2]
[1,0] [1,1] [1,2]
[2,0] [2,1] [2,2]
so that Ideally if I access the position (2,2) I'll get the array [1 1], which represent a point.

回答(1 个)

Matt J
Matt J 2017-2-19
[I,J]=ndgrid(0:2,0:2);
A=reshape([I(:),J(:)].', [2,1,3,3]);
A=permute(A,[2,1,3,4]);
>> A(:,:,2,2)
ans =
1 1

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by