Matlab find 不适用于高维数组?
说 A = 兰特(2,2,2); [a,b,c] = find(A == A(1,2,2))
我得到 a=1 b=4 c=1
什么?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
说 A = 兰特(2,2,2); [a,b,c] = find(A == A(1,2,2))
我得到 a=1 b=4 c=1
什么?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
试试这个:
来源:查找,ind2sub
Try this:
Source: find, ind2sub
查找仅在您尝试将其应用于二维数组时才有效。
Matlab Central 提供了一些可以处理 n 维数组的函数。
Find only works as you're trying to apply it for 2 dimensional arrays.
There are a few functions available over at Matlab Central that will do n-dimensional arrays.
使用等式
==
而不是赋值运算符=
。请参阅 FIND 的文档。输出参数并不适用于所有方向,仅适用于行和列。 MATLAB 似乎沿着第二个方向连接第三个方向并返回第四列。最后一个参数等于 1,因为只有一个匹配项。
Use equality
==
instead of assignment operator=
.See documentation for FIND. output arguments are not for all directions, only rows and columns. It seems MATLAB concatenate the 3rd direction along the 2nd and returns 4th column. The last argument equals 1 because you have only one match.
FIND 函数的输出是两组索引(
a
和b
)以及这些索引处的值 (c
)。对于大于 2 维的矩阵,第二个索引将为 线性索引。在您的示例中,您在执行
A == A(1,2,2)
时创建了一个逻辑数组。该逻辑数组在索引(1,2,2)
处的值为1
(即true
),被传递给 < href="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/find.html" rel="nofollow noreferrer">FIND 函数。该非零值的位置位于矩阵的第一行(输出a = 1
)和其余维度内的第四个线性索引(输出b = 4
)。1
的非零值是c
的输出。The outputs from the FIND function are two sets of indices (
a
andb
) and the values at those indices (c
). For matrices greater than 2 dimensions, the second index will be a linear index.In your example, you create a logical array when you do
A == A(1,2,2)
. This logical array, which has a value of1
(i.e.true
) at index(1,2,2)
, is passed to the FIND function. The position of this non-zero value is in the first row of the matrix (outputa = 1
) and the fourth linear index within the remaining dimensions (outputb = 4
). The non-zero value of1
is output forc
.