How can I find the maximum values in each range of a list in Mathematica?

时光毁灭记忆、已成空白 提交于 2019-12-12 04:37:27

问题


I can do this in MATLAB easily but I'm trying to do it Mathematica. I have a 27000 element (15 minutes*30 measurements per second) list of wind speed values. I want to find the max value in each 2700 element (90 second) range and output it to a vector. Here is the MATLAB code:

N = length(AlongWS);
SegTime = 90;
NSeg = (N/30)/90;
Max90 = zeros(NSeg,1);
Incr = N/NSeg;
for i = 1:NSeg
    Max90(i,1) = max(AlongWS((i-1)*Incr+1:(i*Incr),1));
end

Here is what I've typed in Mathematica:

N = Length[AlongWS]
SegTime = 90
NSeg = (N/30)*60/SegTime
Max90 = {}
Incr = N/NSeg
For[
  i = 1, i < NDiv + 1, i++, 
  maxWS[[i]] = Max[AlongWS[[(i - 1)*Incr + 1 ;; (i*Incr)]]]
]

回答1:


Try this:

Max /@ Partition[AlongWS, 2700]

This partitions AlongWS into sub-lists of length 2700, and then maps Max[] across the sub-lists, yielding a list of the maximum values of each 2700 element range.



来源:https://stackoverflow.com/questions/25966418/how-can-i-find-the-maximum-values-in-each-range-of-a-list-in-mathematica

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!