필터 지우기
필터 지우기

How can I find a maximum mean value of row with given 2D array?

조회 수: 1 (최근 30일)
minsoo kim
minsoo kim 2017년 12월 3일
답변: Star Strider 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.
Someone said that
maxRow=find(max(mean(S,2)));
i = maxRow
this code could solve the problem but unfortunately, the code above only returns 1.
Any ideas?

채택된 답변

Star Strider
Star Strider 2017년 12월 3일
Try this:
max_mean_row_idx = find(mean(S,2) == max(mean(S,2)))
max_mean_row = mean(S(max_mean_row_idx,:),2)
if there could be several rows with the same maximum row mean,
or:
[max_mean_row,max_mean_row_idx] = max(mean(S,2))
if you only want the first maximum row mean.

추가 답변 (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!