maximum values in vector
조회 수: 7 (최근 30일)
이전 댓글 표시
hi everyone, i have a vector consist of 5000 elements and i need to find the maximum values for 2000 elements with their real index , plz can anyone help me in that? thx
댓글 수: 0
답변 (2개)
Star Strider
2015년 3월 30일
편집: Star Strider
2015년 3월 30일
The max function will return only the first maximum in the array if there are more than one. To find all of them, use find:
Example:
Vector = randi(5, 1, 15)
MaxValuesIdx = find(Vector == max(Vector))
produces (in this instance):
Vector =
3 1 2 5 1 3 5 3 4 5 5 2 4 2 1
MaxValuesIdx =
4 7 10 11
EDIT — To get the highest 2000 values, use the sort function.
댓글 수: 0
Image Analyst
2015년 3월 30일
Which 2000? The first 2000? Try this
[maxValue, indexOfMaxValue] = max(yourVector(1:2000));
What does "without changing positions mean"? Do you want an array of the same length but all zeros except for the max being in its original location? If so
output = zeros(size(yourVector)); % Initialize
yourVector(indexOfMaxValue) = maxValue; % Assign that one element
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!