フィルターのクリア

maximum values in vector

2 ビュー (過去 30 日間)
RAAD AL-DULAIMI
RAAD AL-DULAIMI 2015 年 3 月 30 日
編集済み: Star Strider 2015 年 3 月 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

回答 (2 件)

Star Strider
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.

Image Analyst
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
  1 件のコメント
RAAD AL-DULAIMI
RAAD AL-DULAIMI 2015 年 3 月 30 日
thanx for responding ,,, i mean that i need the highest 2000 values on these 5000 . and the real index of those 2000 in the vector

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by