Matlab find 不适用于高维数组?

发布于 2024-09-08 12:06:23 字数 90 浏览 7 评论 0 原文

说 A = 兰特(2,2,2); [a,b,c] = find(A == A(1,2,2))

我得到 a=1 b=4 c=1

什么?

say
A = rand(2,2,2);
[a,b,c] = find(A == A(1,2,2))

I got
a=1
b=4
c=1

what?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

情释 2024-09-15 12:06:23

试试这个:

[a,b,c] = ind2sub(size(A), find(A==A(1,2,2)))

来源:查找ind2sub

Try this:

[a,b,c] = ind2sub(size(A), find(A==A(1,2,2)))

Source: find, ind2sub

死开点丶别碍眼 2024-09-15 12:06:23

查找仅在您尝试将其应用于二维数组时才有效。

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.

新雨望断虹 2024-09-15 12:06:23

使用等式 == 而不是赋值运算符 =

A = rand(2,2,2); [a,b,c] = find(A == A(1,2,2))

请参阅 FIND 的文档。输出参数并不适用于所有方向,仅适用于行和列。 MATLAB 似乎沿着第二个方向连接第三个方向并返回第四列。最后一个参数等于 1,因为只有一个匹配项。

Use equality == instead of assignment operator =.

A = rand(2,2,2); [a,b,c] = find(A == A(1,2,2))

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.

不乱于心 2024-09-15 12:06:23

FIND 函数的输出是两组索引(ab)以及这些索引处的值 (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 and b) 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 of 1 (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 (output a = 1) and the fourth linear index within the remaining dimensions (output b = 4). The non-zero value of 1 is output for c.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文