How to pick next value from vectors based on a condition?

조회 수: 2 (최근 30일)
Evans Gyan
Evans Gyan 2019년 5월 13일
댓글: Evans Gyan 2019년 5월 14일
Assuming i have a vector
A = [ 7.7 213.1 9.5 227.5 12.5 6.8 100.8 5.3 7.2 99.4]
I want to pick a value that is maximum and is greater or equal to the index 5.
In this case my answer would be 100.8 and is of index 7.
Thanks in advance

채택된 답변

Andrei Bobrov
Andrei Bobrov 2019년 5월 13일
m = 5;
[value,ii] = max(A(m:end));
index = ii + m - 1;
  댓글 수: 2
Evans Gyan
Evans Gyan 2019년 5월 13일
Thanks a million.
Evans Gyan
Evans Gyan 2019년 5월 14일
If i want to pick say three highest values from the vector A together with their index, How do i go by it? In this case the values to be selected will be
val = 227.5 213.1 100.8
idx = 4 2 7

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

추가 답변 (1개)

Alex Mcaulley
Alex Mcaulley 2019년 5월 13일
max(A(5:end))

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by