Indexing in a vector
조회 수: 2 (최근 30일)
이전 댓글 표시
I am trying to extract maximum value from a vector by max() function,however I need to know the index of this value in the vector in order to use this indexing in performing another operation by writing a script file.How to know the index of the element in the array?
댓글 수: 2
the cyclist
2020년 8월 16일
You refer to your input as both a "vector" (one-dimensional) and an array (could be any dimension, but typically two).
Which is it?
채택된 답변
the cyclist
2020년 8월 16일
Please see my comment.
If your input is a vector (i.e. one-dimensional), then
[maxValue indexToMaxValue] = max(inputVector);
댓글 수: 0
추가 답변 (1개)
Sara Boznik
2020년 8월 16일
r=triu(r);
r;
w=min(r(r>0));
b=max(r(:));
[m,n]=find(r==w);
fprintf(id,'Minimum %.4f.\n',w);
for i=1:length(m)
fprintf(id,'Points %d in %d.\n',m(i),n(i));
end
[m,n]=find(r==b)
fprintf(id,'Maksimum %.4f.\n',b)
fprintf(id,'Points %d in %d.\n',m,n);
Here is part of my code where we searching the min and max.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!