【问题标题】:find common indices that satisfy 2 conditions in matlab在matlab中找到满足2个条件的公共索引
【发布时间】:2017-11-20 18:27:25
【问题描述】:

我有一个 2D 且非常大 (8000x6000) 的数组。 同一个数组满足两个条件(cond1 和 cond2),我想调和它们,找到同时满足这两个条件的公共索引

F=rand(8000,6000);
ind1=find(F>0.5);ind1 stores indices that satisfy cond1

第二个条件(cond2)是索引是否满足条件。

newF=zeros(8000,6000);
[x,y]=meshgrid(1:6000,1:8000);
newF(x+y>200)=1;

新的数组newF在不满足新条件时为0,满足条件时为1。

我想找到同时满足这两个条件的 F 和 newF 的公共索引。 当我试图找到 ind2(r,c)

 [r,c]=find(newF>0) 

我无法协调 ind1 和 r,c 以找到公共索引。 有人可以帮帮我吗?

【问题讨论】:

  • 索引存储在 cond1 中。谢谢。
  • 完成!谢谢。

标签: arrays matlab indices


【解决方案1】:

将通过应用条件获得的逻辑矩阵乘以element wise,然后使用find 查找公共行和列下标。即

[r, c] = find((F>0.5) .* (newF>0));    
% .* is also replaceable by &. Use whichever is faster

【讨论】:

  • 谢谢。有效。就我而言,使用 & 会快得多。
猜你喜欢
  • 2018-05-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-11-27
  • 2023-02-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多