Discussion:
index of max value of each column array
turbofib
2018-10-19 23:49:58 UTC
Permalink
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
Andreas Weber
2018-10-20 09:49:34 UTC
Permalink
Post by 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
turbofib
2018-10-20 10:08:02 UTC
Permalink
thank you very good


with what meaning is used ~ ?



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html
Andreas Weber
2018-10-20 14:49:16 UTC
Permalink
Post by 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.

Loading...