Coordinates of max in multidimensional arrays

2 vues (au cours des 30 derniers jours)
Anita
Anita le 31 Mai 2011
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.

Réponse acceptée

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

Connectez-vous pour commenter.

Plus de réponses (1)

KYAW KYAW
KYAW KYAW le 27 Oct 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

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by