# Location of maximum number in matrix??

41 visualizzazioni (ultimi 30 giorni)
Maruti Patil il 20 Apr 2015
Modificato: Stephen23 il 20 Apr 2015
%Suppose I have a matrix
A=[2 3 4;
5 6 7;
8 9 0];
%I want to Find the location of maximum number in the matrix ie of 9.
%How to find it??
c=max(A); % what to do next ?
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Stephen23 il 20 Apr 2015
Modificato: Stephen23 il 20 Apr 2015
Simply use the output indices returned by max function:
>> A = [2 3 4; 5 6 7; 8 9 0];
>> [B,I] = max(A(:))
B =
9
I =
6
where I is a linear index into A:
>> A(I)
ans =
9
Note you can convert linear indices to subscript indices using the function ind2sub:
>> [R,C] = ind2sub(size(A),I)
R =
3
C =
2
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Più risposte (1)

Julia il 20 Apr 2015
Hi,
you have to take the "double maximum", since your c gives a vector. Then you can use the find() function.
>> c=max(max(A))
>> B=find(A==c)
B is just a number. To see how Matlab uses linear indexing click the following link:
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Operators and Elementary Operations in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by