How to get coordinates of largest element in an array?

2 views (last 30 days)
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?

Answers (2)

KSSV
KSSV on 21 Jul 2022
[val,idx] = max(RHSvec) ;
[i,j] = ind2sub(size(RHSvec),idx') ;
[i j]
  2 Comments
KSSV
KSSV on 21 Jul 2022
May be you are looking for max along columns...
TRy:
[val,idx] = max(RHSvec,[],2) ;

Sign in to comment.


Stephen23
Stephen23 on 21 Jul 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

Tags

Community Treasure Hunt

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

Start Hunting!