Find maximum value of array within specified range, consecutively

I have a 3384x5 array of which the first and last 20 rows are shown in the pictures below.
Problem: I want to find the maximum value of column 3 within the specified range of column 2.
Problem example:
In the 2th column I have specified a range from 0.0 until 0.011.
Within this range of the 2th column I go to the 3th column. In the 3th column I search for the maximum value which corresponds to the value of the 2th column.
When the maximum value in the 3th column has been found with the corresponding value of the 2th column, than there will be a new range specified in the 2th column. The new range will be from 0.011 until 0.022, so the range increases with 0.011 every time.
Within the new range (0.011 until 0.022) I go again to the 3th column and search for the maximum value with the corresponding value of the 2th column
This loop continues until the last possible range in the 2th column is reached.
Result: All the maximum values found with the corresponding value of the 2th column have to be stored in a new array or matrix.
Until now I have not been able to solve this problem. Any solution and/or help would be very appreciated.

 採用された回答

Cris LaPierre
Cris LaPierre 2020 年 8 月 22 日

0 投票

Assuming you know the ranges a priori, something like this might work. Note that I haven't tested this as I'm not going to try to transcribe your data.
% Define edges of ranges
rng = 0:0.011:0.2090
% Assign the data in column 2 to a predefined range
G = discretize(data(:,2),rng);
% Find the max value in each range
rMax = splitapply(@max,data(:,3),G)

6 件のコメント

Tessa Kol
Tessa Kol 2020 年 8 月 22 日
Thank you very much!
This code succesfully returned all the maximum values within the defined range. But how can I retrieve the values from the 2th column that correspond to these obtained maximum values?
Cris LaPierre
Cris LaPierre 2020 年 8 月 22 日
Add this line of code at the bottom.
col2val = splitapply(@(x,y) {x(y==max(y))},data(:,2),data(:,3),G)
Tessa Kol
Tessa Kol 2020 年 8 月 23 日
Thank you so much for all the help!
gowtham balu
gowtham balu 2021 年 11 月 25 日
Hai Sir,
I have a data which contains two columns and 10k rows of data,
x axis- time (1st column)
y-axis - load (2nd column)
for each 0.5 sec I want to check for the corresponding max and min value in that cycle
1 cycle= 0.5 sec, totally= 10k cycles
Attachment: text file of the data(time_fload.zip)
please help.......this seems to be simple concept but i couldn't do this in matlab..I am trying for many days
Thank you,
gowtham
gowtham balu
gowtham balu 2021 年 11 月 25 日
編集済み: gowtham balu 2021 年 11 月 25 日
for each 0.5 secondsin x axis I want to find the corresponding load value in the y-axis(2nd column)
sorry 10k cycles and 1000000 rows
Cris LaPierre
Cris LaPierre 2021 年 11 月 25 日
編集済み: Cris LaPierre 2021 年 11 月 25 日
Please create a new question

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

その他の回答 (1 件)

Steven Lord
Steven Lord 2020 年 8 月 22 日

0 投票

Use the groupsummary function.

カテゴリ

製品

リリース

R2020a

質問済み:

2020 年 8 月 22 日

編集済み:

2021 年 11 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by