필터 지우기
필터 지우기

Coordinates of max in multidimensional arrays

조회 수: 4 (최근 30일)
Anita
Anita 2011년 5월 31일
Dear Experts,
May I have some help? Being a beginner I got stocked with finding the coordinates of max values in a 3-dimensional array with respect to the 3rd dimension. I am trying to do this:
IND=max(val,[],3);
s=[2,61,1500];
[i,j,g]=ind2sub(s,IND)
where val is the original 3-D array and s is the size of val. For this I got the following error message:
??? Error using ==> rem Arguments must be real.
Error in ==> ind2sub at 35 vi = rem(ndx-1, k(i)) + 1;
I don't really see what should I do and I would very much appreciate any ideas...
thanks in advance.

채택된 답변

Walter Roberson
Walter Roberson 2011년 5월 31일
[themax,IND] = max(val,[],3);
That is, you were getting the maximum itself instead of its index.
  댓글 수: 2
Anita
Anita 2011년 5월 31일
thanks Walter, it is working now.
Anita
Anita 2011년 6월 1일
May I have one more question? I got kind of a strange answer so I might have misunderstood what max with respect to a dimension means. May val matrix was generated by looping through the 3 dimensions, and what I need is to get the index of the max value in the matrix with respect to the 3rd dimension for each combination of the first two dimensions. This is like where is the max in each of 3rd-dim-"column", ie. for dim1=1 and dim2=1, for dim1=1 and dim2=2, etc. However, this command does something else because I don't get back my first-2-dim-combination indices going 1-by-1. What did I do wrong?

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

추가 답변 (1개)

KYAW KYAW
KYAW KYAW 2011년 10월 27일
Dear Walter,
I would like to get the max of Y interms same X values. e.g X = [4 4 4 4 4 5 5 6 6 6....] Y = [10 11 12 13 24 25 34 24 23 ....]
I want to have X = [ 4 5 6 ...] Y = [24 34 24]
Only one X and one Y on the multiple of Y in terms of X
Pls advise me since I was stuck on it n need to finish up tomorrow.
Thankd and best regards Kyaw

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by