How can I find the maximum values in each range of

2019-09-19 02:36发布

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条回答
放荡不羁爱自由
2楼-- · 2019-09-19 03:01

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.

查看更多
登录 后发表回答