finding the max values

조회 수: 8 (최근 30일)
hanan abu elhejaa
hanan abu elhejaa 2018년 1월 20일
답변: Walter Roberson 2018년 1월 20일
if i have an array and a number k how can I find the biggest k number in the array . but the number should be according there positing in the array : arr= [ 1 9 4 7 38 8] k= 4 the ans must be = [ 9 7 38 8]

답변 (3개)

ANKUR KUMAR
ANKUR KUMAR 2018년 1월 20일
편집: ANKUR KUMAR 2018년 1월 20일
arr= [ 1 9 4 7 38 8]
k= 4;
[arr1 b]=sort(arr,'descend');
b1=b(1:k)
arr(sort(b1,'ascend'))
  댓글 수: 1
hanan abu elhejaa
hanan abu elhejaa 2018년 1월 20일
thank you so much :)

댓글을 달려면 로그인하십시오.


Star Strider
Star Strider 2018년 1월 20일
See if this does what you want:
k = 4;
arr = [ 1 9 4 7 38 8];
Result = arr(arr > k)
Result =
9 7 38 8
  댓글 수: 1
Walter Roberson
Walter Roberson 2018년 1월 20일
The question appears to want k to be the number of values to return.

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2018년 1월 20일
With R2017b or later use maxk https://www.mathworks.com/help/matlab/ref/maxk.html
To get the elements in vector order use the two output form and ignore the first output and index the original vector at sort() of the second output

카테고리

Help CenterFile Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by