How to find a row that have maximum mean value in 2D array?

3 visualizaciones (últimos 30 días)
minsoo kim
minsoo kim el 2 de Dic. de 2017
Comentada: KL el 3 de Dic. de 2017
Let's say I have a 2D array S(m,n).
What I want to do is to find a row that has the biggest mean value. I'll call this row as 'i'th row.
So my matlab code was like this.
[i]=find(S==max(mean(S)));
[i]
But matlab just shows "ans = []" which means, there is something wrong with my code.
The problem is, I have no idea how to fix it.
Any ideas?

Respuesta aceptada

KL
KL el 2 de Dic. de 2017
Editada: KL el 3 de Dic. de 2017
You'd need
[maxVal, maxInd] = max(mean(S,2))
mean with parameter 2 calculates mean on the second dimension and then you find the max and it's index.
  3 comentarios
minsoo kim
minsoo kim el 3 de Dic. de 2017
uh....I think there are some mistakes in your code.
maxRow = find(max(mean(S,2)))
This only returns 1.
KL
KL el 3 de Dic. de 2017
You're right, using find wasn't the best choice. You can simply use the second output of max.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!