# find the maximum value in within a specific range?

3 views (last 30 days)
Kim Arnold on 3 May 2023
Commented: Kim Arnold on 3 May 2023
Let's say I have a range of numbers within 50-61 (i.e. 50.36, 50.94, 51.45. 51.86, 51.93 etc.). Each of those numbers have an assigned intensity value ranging from 1-1000. I would now like to find for each number the maximum assigned intensity value (i.e. 50-51, 51-52, 52-53 etc.).
Lets take the example below for numbers 50-52:
number intensity
50.36 2
50.94 500
51.45 40
51.86 253
51.93 290
52.16 960
52.39 15
I would like to know the ID of rows which show the maximum value within for each integer/whole number (i.e. for 50 the max value would be 500 which is ID2, for 51 it is 290 and therefore ID5 etc.). What would be the easiest way to get those IDs? A smart way to use the max function within each number area. Thank you very much for your help!

KSSV on 3 May 2023
A = [50.36 2
50.94 500
51.45 40
51.86 253
51.93 290
52.16 960
52.39 15];
% max with 50
A1 = A(fix(A(:,1))==50,:) ;
[val,idx] = max(A1(:,2))
Kim Arnold on 3 May 2023
Dear KSSV
Thanks for the input, like this I could easily write a for loop. Thank you!