Return Values that are Between Two Values

I have this vector:
w_sorted = [0;0;0;0;1;2;19;60;78];
target = 2;
threshold = 20;
lower_thold = abs(target-threshold);
upper_thold = abs(target+threshold);
series = all(w_sorted >= lower_thold & w_sorted <= upper_thold);
I need series to return all values in the w_sorted vector that are between the lower and upper threshold.
However, I need series to return the actual values, not the logical, which all currently does. I've tried the following which did not work as I needed it to:
series = w_sorted(w_sorted > low_range & w_sorted < up_range);
series = w_sorted(w_sorted(:,1) >= low_range & w_sorted(:,1) <= up_range);
series = w_sorted < low_range | w_sorted > up_range;

답변 (1개)

As per my understanding you want to get the values between the lower and upper threshold from your vector.
I will try to explain it using your code with minor change.
w_sorted = [0;0;0;0;1;2;19;60;78];
target = 2
target = 2
threshold = 20
threshold = 20
lower_thold = abs(target-threshold)
lower_thold = 18
upper_thold = abs(target+threshold)
upper_thold = 22
series = w_sorted(w_sorted >= lower_thold & w_sorted <= upper_thold)
series = 19

댓글 수: 3

Tiffany
Tiffany 2022년 11월 2일
Hi,
So I need to create a mean from that sum...Is there a way I can count the number of values in that array as well?
You don't need the number of values. You can simply use
m = mean(series)
Tiffany
Tiffany 2022년 11월 2일
It doesn't have a number of elements to divide it, so it comes back as NaN?

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

카테고리

도움말 센터File Exchange에서 Financial Toolbox에 대해 자세히 알아보기

제품

질문:

2022년 11월 1일

댓글:

2022년 11월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by