필터 지우기
필터 지우기

From 2 given values find the range from a vector

조회 수: 2 (최근 30일)
Alexandros Samp
Alexandros Samp 2016년 8월 8일
편집: Stephen23 2016년 8월 9일
for example if i have a vector D=[110 140 160 225 280 315 355 400 450 500] and values Dmin=112 and Dmax=356 (always find the value rounded to the bigger number of the vector). i Want to find Range=[140 160 225 280 315 355 400]
Thank you

답변 (3개)

Azzi Abdelmalek
Azzi Abdelmalek 2016년 8월 8일
편집: Azzi Abdelmalek 2016년 8월 8일
Edit
D=[110 140 160 225 280 315 355 400 450 500]
Dmin=112
Dmax=356
ii1=find(D>=Dmin,1)
ii2=find(D>=Dmax,1)
out=D(ii1:ii2)
  댓글 수: 1
Stephen23
Stephen23 2016년 8월 8일
Note that this method will return an empty vector when Dmax is >= max(D). This might be undesired behavior.

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


Stephen23
Stephen23 2016년 8월 8일
편집: Stephen23 2016년 8월 8일
D = [110,140,160,225,280,315,355,400,450,500]
Dmin = 112;
Dmax = 356;
idx = Dmin<=D & [true,D(1:end-1)<=Dmax];
out = D(idx);
and the output:
>> out
out =
140 160 225 280 315 355 400

Alexandros Samp
Alexandros Samp 2016년 8월 8일
This is my problem that Dmax might be out of bound and it returns an empty matrix.
  댓글 수: 3
Alexandros Samp
Alexandros Samp 2016년 8월 8일
If Dmax=700 and Dmin=340 i want to take the Range=[355 400 450 500], from the Dmin value till the end of the vector
Stephen23
Stephen23 2016년 8월 8일
편집: Stephen23 2016년 8월 9일
@Alexandros Samp: Have you actually tried my answer yet? My answer does exactly what you are requesting. Here, I can show you for the third time that it gives you the correct output:
D = [110,140,160,225,280,315,355,400,450,500]
Dmin = 340;
Dmax = 700;
idx = Dmin<=D & [true,D(1:end-1)<=Dmax];
out = D(idx)
and the output:
>> out
out =
355 400 450 500

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by