Index = Index+ Column -1
Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Ältere Kommentare anzeigen
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
Antworten (1)
Roger Stafford
am 8 Mär. 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.
Diese Frage ist geschlossen.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!