필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
minsoo kim
minsoo kim 2017년 12월 2일
댓글: KL 2017년 12월 3일
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?

채택된 답변

KL
KL 2017년 12월 2일
편집: KL 2017년 12월 3일
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
minsoo kim
minsoo kim 2017년 12월 3일
uh....I think there are some mistakes in your code.
maxRow = find(max(mean(S,2)))
This only returns 1.
KL
KL 2017년 12월 3일
You're right, using find wasn't the best choice. You can simply use the second output of max.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!