Index = Index+ Column -1
정보
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
Roger Stafford
2015년 3월 8일
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.
댓글 수: 0
이 질문은 마감되었습니다.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!