201119-Matlab读取最大值或次大值及索引

引言

默写情况,需要获取最大值或次大值及对应的索引,matlab版使用的函数是find和sort。
参考网址:https://stackoverflow.com/questions/13669520/get-second-max-element-in-matlab
代码如下:

aa=sort(a);
find(a==aa(end-1))
[~, idx] = sort(A);
A(idx(end)) % is the max value
A(idx(end-1)) % is the second max value

你可能感兴趣的:(Matlab)