Excel 求向量中特定数量值的最大和-Matlab
我有一个有8760个值的向量,这些值可能是1.2,3.0,7.6,2.5,8.4,6.3等等,我想找到这24个连续的值,它们给出了最大和。我也想知道第一个值的具体位置是这个和 向量是一个Excel文件,在Matlab中读取为Pload=xlsread'demand.xlsx' 将值放入A列。在B24中输入: 把这个抄下来 最后使用:Excel 求向量中特定数量值的最大和-Matlab,excel,matlab,Excel,Matlab,我有一个有8760个值的向量,这些值可能是1.2,3.0,7.6,2.5,8.4,6.3等等,我想找到这24个连续的值,它们给出了最大和。我也想知道第一个值的具体位置是这个和 向量是一个Excel文件,在Matlab中读取为Pload=xlsread'demand.xlsx' 将值放入A列。在B24中输入: 把这个抄下来 最后使用: =MAX(B24:B7860) 要获得位置,请使用=MATCH如果您坚持使用Matlab,可以使用conv卷积函数为您求和,然后找到最大值的位置: 假设数据在一个
=MAX(B24:B7860)
要获得位置,请使用=MATCH如果您坚持使用Matlab,可以使用conv卷积函数为您求和,然后找到最大值的位置: 假设数据在一个名为a的向量中,我称nc为求和的连续数据数:
nc = 24 ; %// number of consecutive values to sum
kn = ones(nc,1) ; %// define a kernel for the convolution
C = conv(A,kn) ; %// calculate a "moving sum"
[~,idx] = max(C) ; %// find the max of the convolution result
idx = idx - nc + 1 ; %// The starting index of the FIRST maximum sum is here
如果您有多个相同的最大值,这将只返回第一个的索引。首先添加您迄今为止尝试过的内容。
nc = 24 ; %// number of consecutive values to sum
kn = ones(nc,1) ; %// define a kernel for the convolution
C = conv(A,kn) ; %// calculate a "moving sum"
[~,idx] = max(C) ; %// find the max of the convolution result
idx = idx - nc + 1 ; %// The starting index of the FIRST maximum sum is here