如何在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.