避免 Matlab 矩阵运算中的 for 循环
我有一个大的 4 维矩阵,我希望 1)找到这些维度中 2 个维度的最小值(即 4000x4000 结果),然后 2)计算最后两个维度中小于(可以说)的元素数量最小值的 5 倍(即给出的结果为 4000x4000)。我有点困惑如何在不恢复 for 循环的情况下执行此操作
一些代码可能有助于我的描述:
A = rand([4000,4000,7,7]);
B(:,:) = min(A(:,:,1:7;1:7)); % this isn't quite right?
C = size( A < 5*B ) % obviously totally wrong
任何指针都会很棒 - 非常感谢!
I have a large 4 dimensional matrix, and I wish to 1) find the minimum of 2 of those dimensions (i.e. a 4000x4000 result) and then 2) count the number of elements in those last two dimensions that are less than (lets say) 5 times the minimum (i.e giving a result of 4000x4000). I'm a bit stumped as to how to do this without reverting to for loops
Some code might aid my description:
A = rand([4000,4000,7,7]);
B(:,:) = min(A(:,:,1:7;1:7)); % this isn't quite right?
C = size( A < 5*B ) % obviously totally wrong
any pointers would be great - many thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我理解正确的话,以下应该可以完成这项工作:
If I understood this correctly, the following should do the job:
首先,它应该是
rand([4000,4000,7,7])
其次,要使用 min,你必须执行类似
min(A, [], 1)
code> (将 1 替换为尺寸)第三,假设您有
A
和B
,您需要C = sum(sum(A < 5*B) )
First, it should be
rand([4000,4000,7,7])
Second, to use min, you have to do something like
min(A, [], 1)
(replace 1 with the dimension)Third, assuming you had
A
andB
, you wantC = sum(sum(A < 5*B))