Find maximum value for every four hours

1 view (last 30 days)
Dear reader,
I have a dataset containing of a datetime array and significant wave height array for every hour between 1950 and 2020. See an example of the first date of my data below:
'01-Jan-1950 00:00:00' 1.15940845676950
'01-Jan-1950 01:00:00' 1.10887721731543
'01-Jan-1950 02:00:00' 1.06369417473789
'01-Jan-1950 03:00:00' 1.02607237602026
'01-Jan-1950 04:00:00' 0.993061091851364
'01-Jan-1950 05:00:00' 0.962262854665854
'01-Jan-1950 06:00:00' 0.937366076102719
'01-Jan-1950 07:00:00' 0.917448653252210
'01-Jan-1950 08:00:00' 0.903985950769921
'01-Jan-1950 09:00:00' 0.893289557016870
'01-Jan-1950 10:00:00' 0.871159087182972
'01-Jan-1950 11:00:00' 0.853823552479750
'01-Jan-1950 12:00:00' 0.861015955175768
'01-Jan-1950 13:00:00' 0.910256250556192
'01-Jan-1950 14:00:00' 0.963553798739499
'01-Jan-1950 15:00:00' 1.03695319035526
'01-Jan-1950 16:00:00' 1.14262618381213
'01-Jan-1950 17:00:00' 1.26083977684154
'01-Jan-1950 18:00:00' 1.42718714175968
'01-Jan-1950 19:00:00' 1.59205914202222
'01-Jan-1950 20:00:00' 1.70437127642926
'01-Jan-1950 21:00:00' 1.74162423398299
'01-Jan-1950 22:00:00' 1.77998371502842
'01-Jan-1950 23:00:00' 1.80672469941104
For my analysis, I want to reduce the data so that only the highest value for significant wave height and the corresponding date + time is obtained. Preferably, I want to find a way that finds the index for the maximum value of the significant wave height so that the corresponding date and time can be obtained as well. An example of the envisioned result is:
'01-Jan-1950 00:00:00' 1.15940845676950
'01-Jan-1950 05:00:00' 0.962262854665854
'01-Jan-1950 08:00:00' 0.903985950769921
'01-Jan-1950 15:00:00' 1.03695319035526
'01-Jan-1950 19:00:00' 1.59205914202222
'01-Jan-1950 23:00:00' 1.80672469941104
I hope that I have made myself clear. Thanks in advance for your help and time.

Accepted Answer

KSSV
KSSV on 1 Dec 2021
Read about reshape. Reshape your data so that one dimension corresponds to four hours and then use max.

More Answers (0)

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!