如何在MATLAB中的矩阵列中找到最大值的索引? [英] How can I find the index of the maximum value in a matrix column in MATLAB?

查看:2909
本文介绍了如何在MATLAB中的矩阵列中找到最大值的索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试查找矩阵中某列的最大值。我想找到它的最大值和行的索引。我该怎么做?

I'm trying to find the maximum value of a certain column in a matrix. I want to find both the maximum value and the index of the row in which it is. How can I do this?

推荐答案

max 命令可以同时找到最大值及其索引。

以下是一个例子:

max command can find both the maximal value and its index.
Here's an example:

>> A = randn(10,3)
A = 
       0.8884     -0.10224     -0.86365
      -1.1471     -0.24145     0.077359
      -1.0689      0.31921      -1.2141
      -0.8095      0.31286      -1.1135
      -2.9443     -0.86488   -0.0068493
       1.4384    -0.030051       1.5326
      0.32519     -0.16488     -0.76967
     -0.75493      0.62771      0.37138
       1.3703       1.0933     -0.22558
      -1.7115       1.1093       1.1174

>> [maxVal maxInd] = max(A)
maxVal =
       1.4384       1.1093       1.5326
maxInd =
     6    10     6

这篇关于如何在MATLAB中的矩阵列中找到最大值的索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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