简体   繁体   English

Excel function 过滤发生阶跃变化的数组

[英]Excel function to filter an array where a step change has occurred

I am trying to filter an array to only include those values that are not within a set distance of a change in that array.我正在尝试过滤数组以仅包含那些不在该数组更改的设定距离内的值。

Here's my example:这是我的例子:

在此处输入图像描述

The input array increases monotonically in steps.输入数组单调递增。 I want to zero out any of the input values from N rows above to N rows below any point where the value changes.我想将任何输入值从上面的 N 行清零到值发生变化的任何点下面的 N 行。 Cell $B$2 holds this "window" value.单元格 $B$2 保存此“窗口”值。

For example, cell A9 (value 11) is different from cell A8 (value 5), so I want to zero out values that come from any cells from A7 to A11 inclusive.例如,单元格 A9(值 11)与单元格 A8(值 5)不同,因此我想将来自 A7 到 A11(包括 A7 到 A11)的任何单元格的值归零。 That is from -N to +N relative the cell where the change occurs, where N=2.即相对于发生变化的单元格从 -N 到 +N,其中 N=2。

I can achieve the required output with non-array functions, using intermediate calculation columns, but since I am processing a large number of columns it would save greatly on spreadsheet real-estate if I could construct a single array formula that operates on the range A4:A25, and uses cell B1 for the size of N. I am using the current Excel Beta, so I have access to LET and LAMBDA if needed.我可以使用非数组函数,使用中间计算列来实现所需的 output,但是由于我正在处理大量列,如果我可以构造一个在范围 A4 上运行的单个数组公式,它将大大节省电子表格房地产:A25,并使用单元格 B1 作为 N 的大小。我正在使用当前的 Excel Beta,因此如果需要,我可以访问 LET 和 LAMBDA。

I have tried various combinations, using SEQUENCE, but I run into the issue that LET (or indeed any array functions) seems to fail if they contain two SEQUENCE statements.我已经尝试了各种组合,使用 SEQUENCE,但我遇到的问题是,如果 LET(或实际上任何数组函数)包含两个 SEQUENCE 语句,它们似乎会失败。

I am continuing to work on this, but if anyone wants to have a try, I would be most grateful!我正在继续努力,但如果有人想尝试一下,我将不胜感激!

UPDATE: This formula does the trick, but needs to be copied down:更新:这个公式可以解决问题,但需要复制下来:

=A4*IF(AVERAGE(OFFSET(A4,-($B$1+1),0,2*($B$1+1),1))<>A4,0,1)

So, while the suggestion of @JvdV was not exactly what I was after, a hat-tip to them for the idea of offsetting the whole column up and down, which led to this:因此,虽然@JvdV 的建议并不完全是我所追求的,但对他们来说,上下偏移整个专栏的想法是一个帽子提示,这导致了这一点:

=LET(input,A4:A25,up,OFFSET(input,-1*(B1+1),0),down,OFFSET(input,B1,0),input*IF(IFERROR(up*down,0)>0,IF(up=down,1,0),1))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM