如何在不循环的情况下找到数组中最大元素的索引?
例如,如果我有:
a = [1 2 999 3];
我想定义一个函数 indexMax
以便 indexMax(a)
返回 3
。
同样适用于定义 indexMin
。
最佳答案
当指定两个输出参数时,内置的 max
函数具有此功能:
a = [1 2 999 3];
[the_max, index_of_max] = max(a)
the_max =
999
index_of_max =
3
min
也是如此。
关于matlab - 数组中最大值和最小值的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14556733/