필터 지우기
필터 지우기

smallest n such that vector(n) < a

조회 수: 2 (최근 30일)
Kaushik
Kaushik 2012년 12월 21일
hi,
is there a efficient way that given a vector "vec" whose elements are monotonic increasing i can find the smallest index such that vec(n) < a. where "a" is some given value.
  댓글 수: 1
Image Analyst
Image Analyst 2012년 12월 21일
편집: Image Analyst 2012년 12월 21일
The smallest/lowest/first index will be the first one (index = 1) like Azzi said. But that is a trivial case and I think you actually mean the highest index, and that is what Wayne gave you code for. Like m = [11 12 13 14 15] and the value = 13.1. The lowest index where m < 13.1 is 1 and the highest is 3. Please confirm/clarify.

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

채택된 답변

Wayne King
Wayne King 2012년 12월 21일
편집: Wayne King 2012년 12월 21일
x = 1:100;
a = 50;
[val,idx] = find(x<a,1,'last');
idx is the index of vec() and val is the value
If the values in the vector are monotonically increasing as you describe, then the 'last' option gives you the last index. Did you really mean you want the "smallest"?

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2012년 12월 21일
편집: Azzi Abdelmalek 2012년 12월 21일
v=[10 12 4 5 9 20]
idx=find(v<5,1)
  댓글 수: 1
Azzi Abdelmalek
Azzi Abdelmalek 2012년 12월 21일
If v is increasing, the first index, if it exist, must be 1

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

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by