如何在MATLAB中的数组中找到最大值及其索引? [英] How can I find the maximum value and its index in array in MATLAB?

查看:2493
本文介绍了如何在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆