find values between constants in vector

조회 수: 2 (최근 30일)
Leor Greenberger
Leor Greenberger 2011년 9월 21일
I have a vector freq_n where I want to find the indices corresponding to values between a and b.
freq_in-10*delta_f <= freq_n <= freq_in+10*delta_f
How would I go about doing this? The find() function seems to only allow one relational operator, unless I am doing something wrong? thanks!

채택된 답변

Sean de Wolski
Sean de Wolski 2011년 9월 21일
idx = X >= a & X <= b;
where X is your vector, a is the lower bound, b is the upper bound. This will be their logical values. If you want numerical indices:
find(idx)

추가 답변 (2개)

Wayne King
Wayne King 2011년 9월 21일
freq = 0:1:500;
[~,indices] = find(freq>20 & freq < 250);
freq(indices)

Leor Greenberger
Leor Greenberger 2011년 9월 21일
ah. I think I got it:
find(freq_n <= freq_in+10*delta_f & freq_n >= freq_in-10*delta_f)
I was initially using && and that wasn't working.

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by