MATLAB:在多维数组中查找值的坐标
我有一个三维数组,我希望能够找到一个特定的值并获得三个坐标。
例如,如果我有:
A = [2 4 6; 8 10 12]
A(:,:,2) = [5 7 9; 11 13 15]
我想找到 7
在哪里,我想获取坐标 i = 1
j = 2
code> k = 2
我尝试过 find(A == 7)
的变体,但还没有任何进展。
谢谢!
I have a three-dimensional array, and I'd like to be able to find a specific value and get the three coordinates.
For example, if I have:
A = [2 4 6; 8 10 12]
A(:,:,2) = [5 7 9; 11 13 15]
and I want to find where 7
is, I'd like to get the coordinates i = 1
j = 2
k = 2
I've tried variations of find(A == 7)
, but I haven't got anywhere yet.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您寻找的函数是
ind2sub
:The function you seek is
ind2sub
:您可以使用 find 来定位数组中的非零元素,但它需要一点算术运算。从文档中:
如果矩阵
M
的维度为axbx c
,则索引(i,j,k)
对于某些值x
是:You can use find to locate nonzero elements in an array, but it requires a little bit of arithmetic. From the documentation:
If the matrix
M
has dimensionsa x b x c
, then the indices(i,j,k)
for some valuex
are: