我想找到矩阵中每行的第n个最小元素。
示例:
n = 2
M = [1, 2, 3; 4, 5, 6; 7, 8 9]
Result = [2, 5, 8]
答案 0 :(得分:4)
首先按第二维对矩阵进行排序(即按升序排序每一行):
n = 2
M = [1, 2, 3; 4, 5, 6; 7, 8 9]
M_SORTED = sort(M,2)
M_SORTED =
1 2 3
4 5 6
7 8 9
矩阵的第n列将包含结果:
RESULT = M_SORTED(:, n)
RESULT =
2
5
8