Index = Index+ Column -1
Información
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Mostrar comentarios más antiguos
Hello All,
I am trying to figure out why does the formula 'Index=Index+Column-1' give a correct answer while finding the index of a maximum value in any matrix. For example:
A=[1 2 3; 40 10 13;17 30 31]
[n,n]=size(A);
for k=1:n-1
[maxV,I]=max(A(k:n,k));
I=I+k-1;
maxV
I
end
I won't get a right answer without using this formula. Can someone please help me know where is this formula 'I=I+k-1' derived from?
Dev
Respuestas (1)
Roger Stafford
el 8 de Mzo. de 2015
Where you write
[maxV,I]=max(A(k:n,k));
the index, 'I', which is returned, is relative to the portion of A that is being presented to 'max'. All 'max' sees when 'k' is equal to 2, is the second and third rows of the second column of A. Naturally it gives 'I' a value of 1 since the maximum occurs in the first row it sees. The code adds a correcting "k-1" to compensate.
This code snippet does not find the maximum values in the columns of A. It checks only its first two columns, and in the second column only the bottom two values.
La pregunta está cerrada.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!