필터 지우기
필터 지우기

Select the max & min values in multi index Matrix

조회 수: 6 (최근 30일)
burcu bilgic
burcu bilgic 2021년 11월 8일
댓글: Image Analyst 2021년 11월 9일
I have a matrix with repetitive values in x and y
for examle:
161 436
161 437
161 523
161 523
162 281
162 457
162 678
I want to find max and min values for every x, for example in this case, I want to end up with two different matrix where I have minimum and maximum values. For examle
min matrix:
161 436
162 281
and max matrix will be
161 523
162 678
each x value is an index and I want to find the min and max value corresponding to that index seperately
Thank you :)

답변 (1개)

Image Analyst
Image Analyst 2021년 11월 8일
You can use splitapply:
m=[161 436
161 437
161 523
161 523
162 281
162 457
162 678];
groupID = findgroups(m(:, 1))
groupID = 7×1
1 1 1 1 2 2 2
minMatrix = splitapply(@min, m, groupID)
minMatrix = 2×2
161 436 162 281
maxMatrix = splitapply(@max, m, groupID)
maxMatrix = 2×2
161 523 162 678
  댓글 수: 2
burcu bilgic
burcu bilgic 2021년 11월 9일
it worked like a charm thank you so much :)
Image Analyst
Image Analyst 2021년 11월 9일
Then could you please click the "Accept this answer" link? Thanks in advance. 🙂

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

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by