Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想创建一个二维向量矩阵。每个向量都应包含其在矩阵中自己位置的 x/y 索引(或 i,j,如果需要)。
基本上我想要这样的东西:
我知道我可以在 for 循环中创建它,但是有更简单的方法吗?Matlab 有这么多有用的功能,它不止一次让我感到惊讶。
meshgrid将让您大部分时间到达那里:
meshgrid
>> [X,Y] = meshgrid(0:2, 0:2) X = 0 1 2 0 1 2 0 1 2 Y = 0 0 0 1 1 1 2 2 2
您通常不能在 Matlab 中拥有“向量矩阵”。另外两个选项:
要实现第二个选项:
coords(:,:,1) = X coords(:,:,2) = Y
一个后续问题:你为什么要这样做?