Coordinates of max in multidimensional arrays

3 次查看(过去 30 天)
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-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