2014-10-05 27 views
17

Chcę znaleźć argmax z wartości w macierzy przez kolumnę, np:pozycja Oktawa maksymalnej wartości w kolumnie

1 2 3 2 3 3 
4 5 6 -> 
3 7 8 

czuję, że należy po prostu być w stanie odwzorować argmax/funkcję posmax ponad kolumny, ale nie widzę szczególnie intuicyjnego sposobu na zrobienie tego w Octave.

Odpowiedz

28

Czytaj max dokumentacja funkcja here

[max_values indices] = max(input); 

Przykład:

input = 

1 2 3 
4 5 6 
3 7 8 

[max_values indices] = max(input) 
max_values = 

4 7 8 

indices = 

2 3 3 
+0

Dzięki! Działa doskonale. –

3
 
In Octave If 
A = 
    1 3 2 
    6 5 4 
    7 9 8 

1) For Each Column Max value and corresponding index of them can be found by 
>> [max_values,indices] =max(A,[],1) 
max_values = 
    7 9 8 
indices = 
    3 3 3 


2) For Each Row Max value and corresponding index of them can be found by 
>> [max_values,indices] =max(A,[],2) 
max_values = 
    3 
    6 
    9 
indices = 
    2 
    1 
    2 

Similarly For minimum value 

>> [min_values,indices] =min(A,[],1) 
min_values = 
    1 3 2 

indices = 
    1 1 1 

>> [min_values,indices] =min(A,[],2) 
min_values = 
    1 
    4 
    7 

indices = 
    1 
    3 
    1