2012-11-28 53 views

回答

33

使用max函数的第二输出参数:

[ max_value, max_index ] = max([ 3 9 1 ]) 
+5

作品倍频太! – sudocoder

3

我的标准溶液是做

index = find(array == max(array), 1); 

它返回等于最大值的第一个元素的索引。你可以用find选项乱动,如果你想,而不是最后一个元素等

1

如果你需要得到各行的最大价值,你可以使用:

array = [1, 2, 3; 6, 2, 1; 4, 1, 5]; 
[max_value max_index] = max(array, [], 2) 

%3, 3 
%6, 1 
%5, 3 
1
 
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 
相关问题