如何在MATLAB中找到数组中的最大值及其索引? [英] How can I find the maximum value and its index in array in MATLAB?
本文介绍了如何在MATLAB中找到数组中的最大值及其索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一个数组,a = [2 5 4 7]
.返回最大值及其索引的函数是什么?
Suppose I have an array, a = [2 5 4 7]
. What is the function returning the maximum value and its index?
例如,在我的例子中,该函数应该返回 7 作为最大值和 4 作为索引.
For example, in my case that function should return 7 as the maximum value and 4 as the index.
推荐答案
函数为max
.要获得第一个最大值,您应该这样做
The function is max
. To obtain the first maximum value you should do
[val, idx] = max(a);
val
是最大值,idx
是它的索引.
val
is the maximum value and idx
is its index.
这篇关于如何在MATLAB中找到数组中的最大值及其索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文