index of max value of each column array

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

index of max value of each column array

turbofib

 a=[4 5 6 7;2 3 1 4;6 7 8 5;9 5 6 4]

i want to know index of max of each column between 1 and 3 rows..

>>a

4 5 6 7
2 3 4 4
6 7 8 5
9 5 6 4

max rows 1:3 is:
4 5 6==>6  =>index 3
2 3 1==>3 => index 2
6 7 8==>8=> index 3
9 5 6==>9==> index 1


answer is : 3 2 3 1


i try it :

[e,g]=find( a(1:3)==max(a(1:3,:)),3-1,"first")

but is not correct...i don't get the correct result






--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: index of max value of each column array

Andreas Weber-6
Am 20.10.18 um 01:49 schrieb turbofib:
>   a=[4 5 6 7;2 3 1 4;6 7 8 5;9 5 6 4]
> i want to know index of max of each column between 1 and 3 rows..


[~, ii] = max (a(:,1:3), [], 2)
ii =

    3
    2
    3
    1



Reply | Threaded
Open this post in threaded view
|

Re: index of max value of each column array

turbofib
This post was updated on .

thank you very good


with what meaning is used ~ ?

another question :
i want to print this max

i try it but it is not correct

a(ii,:)


--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: index of max value of each column array

Andreas Weber-6
Am 20.10.18 um 12:08 schrieb turbofib:
> with what meaning is used ~ ?

octave:1> help ~

  -- ~
      Logical 'not' operator.

      The symbol may also be used to discard outputs of a function that
      are unwanted without using a temporary variable.

           [~, IDX_OF_MAX] = max (X)

      See also: !, not.