Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想在矩阵中找到第三个最大值。我已经有最大值
max(A)
而且我已经有了第二个最大值
max(A(A~=max(A))
但我不能做第三个,请建议并帮助我。
最简单的解决方案是按降序对 的值进行排序A,然后选择第三个排序的元素(如果存在):
A
A_sorted = sort(A(:), 'descend'); third_max = A_sorted(min(3, end));
如果您不允许重复值(例如 A = [10, 10; 9; 2]并且想要 2),请对唯一值进行排序:
A = [10, 10; 9; 2]
A_sorted = sort(unique(A), 'descend');