Finding a maximum period

3 ビュー (過去 30 日間)
Kate
Kate 2017 年 1 月 18 日
コメント済み: Kate 2017 年 1 月 18 日
Hey Guys,
I'm trying to wrap my brain around how to find n maximum or minimum values in a row. I've used grpstats to generate mean values, but need to find the three highest or lowest in a row, so I can't use a sort function:
[m, g]=grpstats(data(:, 2), data(:, 1), {'mean', 'gname'})
m =
16.4605
19.6645
19.0127
20.0246
21.0003
20.0367
15.7379
22.7125
19.9485
20.4098
21.6320
17.6872
g =
'1'
'2'
'3'
'4'
'5'
'6'
'7'
'8'
'9'
'10'
'11'
'12'
Any ideas or functions to suggest? Thanks and all the best.
  2 件のコメント
Walter Roberson
Walter Roberson 2017 年 1 月 18 日
Are you looking for a moving maximum, where every point is replaced by the maximum of the point and the point before and the next point? Are you looking for a single group of three values in a row that has the highest average out of all of the sliding possibilities?
Kate
Kate 2017 年 1 月 18 日
The later, I'm looking for the 3 highest (or lowest) consecutive values. This is a metric called Mean Temperature of the Warmest Quarter. Thanks Walter.

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2017 年 1 月 18 日
If you're looking for the group of 3 elements that have the highest sum (and mean) then you can use conv() or movmean()
threeElementSum = conv(data, [1,1,1], 'same');
[maxSum, indexOfMax] = max(threeElementSum);
This will tell you where the center of the 3 element window is where the values inside that 3 element window have the highest sum of any window location in the data. Is that what you're looking for?
  1 件のコメント
Kate
Kate 2017 年 1 月 18 日
Perfect, convolution is exactly what I was looking for. I appreciate it.

サインインしてコメントする。

その他の回答 (1 件)

Alexandra Harkai
Alexandra Harkai 2017 年 1 月 18 日
If you're looking for the n highest and lowest entry for each row of input data, you can still use the sort function:
[sorted, row_idx] = sort(data, 2);
sorted will contain the sorted data, row_idx will contain the row-wise indices, so:
sorted(:,1:n) % n smallest elements in each row
sorted(:,(end+1-n):end) % n largest elements in each row
row_idx(1,1:n) % indices in rows for the n smallest elements in each row
row_idx(1,(end+1-n):end) % indices in rows for the n largest elements in each row
  1 件のコメント
Kate
Kate 2017 年 1 月 18 日
編集済み: Kate 2017 年 1 月 18 日
It's a great crack, but essentially I can't sort the values, because then the months are split up. Here's an example result of your code:
row_idx((end+1-n):end, 1)
ans =
5
11
8
Indicating May, November and August, which aren't proximal in time. I appreciate the help though.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeData Preprocessing についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by