find the maximum value in within a specific range?

조회 수: 7 (최근 30일)
Kim Arnold
Kim Arnold 2023년 5월 3일
댓글: Kim Arnold 2023년 5월 3일
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
KSSV 2023년 5월 3일
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))
  댓글 수: 1
Kim Arnold
Kim Arnold 2023년 5월 3일
Dear KSSV
Thanks for the input, like this I could easily write a for loop. Thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Performance and Memory에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by