Extract values within interquartile range in array

조회 수: 26 (최근 30일)
Vlatko Milic
Vlatko Milic 2018년 10월 31일
댓글: Sesilia Iileka 2019년 3월 6일
Hi,
I want to extract values within an interquartile range in an array. Let say that the array looks as follows: v= [1 2 3 4 5 6 ......95 96 97 98 99]. The interquartile range is 25 and 75. How can I extract the array values from 25 to 75 to a new array? If possible, can I select other ranges than bottom and top 25%?
Thanks!

채택된 답변

the cyclist
the cyclist 2018년 10월 31일
편집: the cyclist 2018년 10월 31일
Use the quantile command to get whichever quantiles you want.
Then extract using logical indexing (as described on this documentation page).
v = 1:99;
q = quantile(v,[0.25 0.75])
v2 = v(v>q(1) & v<q(2))
  댓글 수: 7
Vlatko Milic
Vlatko Milic 2018년 10월 31일
I see, that sounds reasonable.Thank you for the pedagogic explanation :)
Sesilia Iileka
Sesilia Iileka 2019년 3월 6일
Hi i want kind of the same thing but from a loop
like this:
for i = length(x)
xy = find(u==i | u>i & u4<(i+1)); #xy should find indices of u within that range i.e u(i)>=i<u(i+1)
N(i) = length(xy) #giving me counts of i
end
but then, the last iteration (last value of i) will be wrong by this expression.
how do i correct this please?
Thanks a lot

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

추가 답변 (1개)

madhan ravi
madhan ravi 2018년 10월 31일
편집: madhan ravi 2018년 10월 31일
v=1:100;
new_array = v(v >=25 & v<=75) %values between 25 to 75
new_array1 = v(v<25 | v>75) % values less than 25 and greater than 75
  댓글 수: 6
Vlatko Milic
Vlatko Milic 2018년 10월 31일
No worries, thank you friend :)
Sesilia Iileka
Sesilia Iileka 2019년 3월 6일
Hi i want kind of the same thing but from a loop
like this:
for i = length(x)
xy = find(u==i | u>i & u4<(i+1)); #xy should find indices of u within that range i.e u(i)>=i<u(i+1)
N(i) = length(xy) #giving me counts of i
end
but then, the last iteration (last value of i) will be wrong by this expression.
how do i correct this please?
Thanks a lot

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by