Coordinates of max in multidimensional arrays

2 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Walter Roberson
Walter Roberson il 31 Mag 2011
[themax,IND] = max(val,[],3);
That is, you were getting the maximum itself instead of its index.
  2 Commenti
Anita
Anita il 31 Mag 2011
thanks Walter, it is working now.
Anita
Anita il 1 Giu 2011
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?

Accedi per commentare.

Più risposte (1)

KYAW KYAW
KYAW KYAW il 27 Ott 2011
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

Community Treasure Hunt

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

Start Hunting!

Translated by