简体   繁体   English

矩阵中的最大值的指标

[英]Indices of max values in matrix

Let's say I have the following matrix: 假设我有以下矩阵:

 j = 
 1   2   3   4  
 1   2   3   4  
 5   6   7   8  
 5   6   7   8

I would like to get back the following matrix: 我想找回以下矩阵:

z =  
3 4  
4 4 

My experience with the max command hasn't yielded a result that resembles z, it appears that the max function turns the argument into a column vector. 我对max命令的体验并未产生类似于z的结果,似乎max函​​数将参数转换为列向量。

It appears you want the row and column indices of all occurrences of the maximum computed across all dimensions (ie the maximum is a single value, which possibly appears in several entries). 似乎您希望在所有维度上计算所有出现的最大值的行索引和列索引 (即,最大值是单个值,可能会出现在多个条目中)。 Then: 然后:

[rows, cols] = find(j==max(j(:)));
result = [rows cols];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM