From 2 given values find the range from a vector

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 个)

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 个评论

Note that this method will return an empty vector when Dmax is >= max(D). This might be undesired behavior.

请先登录,再进行评论。

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
This is my problem that Dmax might be out of bound and it returns an empty matrix.

3 个评论

My answer works correctly when Dmax is out of range. Did you try it?
Dmin = 109;
Dmax = 501; % out of range
idx = Dmin<=D & [true,D(1:end-1)<=Dmax];
out = D(idx)
and the output:
>> out
out =
110 140 160 225 280 315 355 400 450 500
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
@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

请先登录,再进行评论。

类别

帮助中心File 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