# How to get coordinates of largest element in an array?

3 visualizaciones (últimos 30 días)
Prerna Mishra el 21 de Jul. de 2022
Respondida: Stephen23 el 21 de Jul. de 2022
I have an array RHSvec that looks as follows:
RHSvec = [-2.37702213697260e+17 -2.33711662054550e+19 -615937600693473 -4.41919914907522e+19 -3.50291921355524e+20;
-2.40560608664763e+29 -2.16934082274551e+19 -5.73988280489045e+15 -5.33311081810851e+17 -1.17461587901498e+20;
-2.32915727020229e+17 -2.45850745864384e+19 -616589732914132 -6.16155763686288e+15 -4.91512660764408e+19;
-2.32993977385979e+17 -2.14986528565165e+19 -2.94155364006571e+15 -3.65210939697662e+15 -2.12320586283470e+23;
-2.41504694091774e+17 -2.14752641506426e+19 -625473159572963 -3.67525135357355e+17 -4.90376317631114e+19;
-2.33465933952372e+17 -2.15460612285011e+19 -9.81511044091666e+20 -4.19405807636241e+15 -4.90257920973114e+19;
-2.34071058671374e+17 -2.15547532573166e+19 -1.43052472228394e+15 -8.62043004357417e+15 -4.90258050787429e+19]
When I do the following:
[RHSval,kprimeind] = max(RHSvec)
I get
RHSval =
1.0e+19 *
-0.0233 -2.1475 -0.0001 -0.0004 -4.9026
And
kprimeind =
3 5 1 4 6
What I want is
kprimeind =
3 5 1 4 6
And
dprimeind =
1 2 3 4 5
Basically I want coordinates (3,1) (5,2), (1,3), (4,4) (6,1)
How do it get this?
##### 0 comentariosMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos

Iniciar sesión para comentar.

### Respuestas (2)

KSSV el 21 de Jul. de 2022
[val,idx] = max(RHSvec) ;
[i,j] = ind2sub(size(RHSvec),idx') ;
[i j]
##### 2 comentariosMostrar 1 comentario más antiguoOcultar 1 comentario más antiguo
KSSV el 21 de Jul. de 2022
May be you are looking for max along columns...
TRy:
[val,idx] = max(RHSvec,[],2) ;

Iniciar sesión para comentar.

Stephen23 el 21 de Jul. de 2022
format long G
M = [-2.37702213697260e+17,-2.33711662054550e+19,-615937600693473,-4.41919914907522e+19,-3.50291921355524e+20;-2.40560608664763e+29,-2.16934082274551e+19,-5.73988280489045e+15,-5.33311081810851e+17,-1.17461587901498e+20;-2.32915727020229e+17,-2.45850745864384e+19,-616589732914132,-6.16155763686288e+15,-4.91512660764408e+19;-2.32993977385979e+17,-2.14986528565165e+19,-2.94155364006571e+15,-3.65210939697662e+15,-2.12320586283470e+23;-2.41504694091774e+17,-2.14752641506426e+19,-625473159572963,-3.67525135357355e+17,-4.90376317631114e+19;-2.33465933952372e+17,-2.15460612285011e+19,-9.81511044091666e+20,-4.19405807636241e+15,-4.90257920973114e+19;-2.34071058671374e+17,-2.15547532573166e+19,-1.43052472228394e+15,-8.62043004357417e+15,-4.90258050787429e+19]
M = 7×5
1.0e+00 * -2.3770221369726e+17 -2.3371166205455e+19 -615937600693473 -4.41919914907522e+19 -3.50291921355524e+20 -2.40560608664763e+29 -2.16934082274551e+19 -5.73988280489045e+15 -5.33311081810851e+17 -1.17461587901498e+20 -2.32915727020229e+17 -2.45850745864384e+19 -616589732914132 -6.16155763686288e+15 -4.91512660764408e+19 -2.32993977385979e+17 -2.14986528565165e+19 -2.94155364006571e+15 -3.65210939697662e+15 -2.1232058628347e+23 -2.41504694091774e+17 -2.14752641506426e+19 -625473159572963 -3.67525135357355e+17 -4.90376317631114e+19 -2.33465933952372e+17 -2.15460612285011e+19 -9.81511044091666e+20 -4.19405807636241e+15 -4.90257920973114e+19 -2.34071058671374e+17 -2.15547532573166e+19 -1.43052472228394e+15 -8.62043004357417e+15 -4.90258050787429e+19
[V,X] = max(M,[],1,'linear');
[R,C] = ind2sub(size(M),X)
R = 1×5
3 5 1 4 6
C = 1×5
1 2 3 4 5
##### 0 comentariosMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos

Iniciar sesión para comentar.

### Categorías

Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by