Select the max & min values in multi index Matrix
1 次查看(过去 30 天)
显示 更早的评论
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 :)
0 个评论
回答(1 个)
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))
minMatrix = splitapply(@min, m, groupID)
maxMatrix = splitapply(@max, m, groupID)
2 个评论
Image Analyst
2021-11-9
Then could you please click the "Accept this answer" link? Thanks in advance. 🙂
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!