MATLAB:查找每行中第 n 个最小的元素
我想找到矩阵中每一行的第 n 个最小元素。
例子:
n = 2
M = [1, 2, 3; 4, 5, 6; 7, 8 9]
Result = [2, 5, 8]
I want to find the n-th smallest element for each row in a matrix.
Example:
n = 2
M = [1, 2, 3; 4, 5, 6; 7, 8 9]
Result = [2, 5, 8]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先按第二维对矩阵进行排序(即按升序对每一行进行排序):
矩阵的第 n 列将包含结果:
First sort the matrix by the second dimension (i.e. sort every row in ascending order):
The n-th column of the matrix will contain the result: