Extract values within interquartile range in array

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!

 Respuesta aceptada

the cyclist
the cyclist el 31 de Oct. de 2018
Editada: the cyclist el 31 de Oct. de 2018
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 comentarios

Thank you, exactly what I was looking for! I just have one question about the follown: Let's say I have 10 000 digits in the cell and select 10% quantile. But my quantile value at 10% and 90 % will be between two integers. How will the function operate then? What values will be selected?
This logical value
v>q(1)
will be true when the value in your vector is strictly larger than the quantile (regardless of whether it is an integer or not). So if all your values in v are integers, it will only select the integers that are larger than the "in-between" quantile value.
okej, good explanation. Thank you again! :)
The cyclist, I tried with : v= 0:10; q = quantile(v,[0.25 0.75])
This gives med 2.25 and 7.75. As it is the quartiles I thought I would get 2.5 and 7.5. What do I do wrong?
the cyclist
the cyclist el 31 de Oct. de 2018
Editada: the cyclist el 31 de Oct. de 2018
You did not do anything wrong, but your expectation was wrong. :-)
Technically, any value between 2 and 3 will qualify as a 0.25 quantile of that vector. The definition is not strict enough to determine a unique value. There are many different procedures for selecting a single value. (See, e.g., this Wikipedia page or this MathWorld page.)
The procedure that MATLAB uses is described on this documentation page.
I see, that sounds reasonable.Thank you for the pedagogic explanation :)
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

Iniciar sesión para comentar.

Más respuestas (1)

madhan ravi
madhan ravi el 31 de Oct. de 2018
Editada: madhan ravi el 31 de Oct. de 2018
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 comentarios

madhan ravi
madhan ravi el 31 de Oct. de 2018
The extraction of ranges can be done by logical indexing.
Yes, but let's say that I don't know what the interquartile range is before the statement. So I don't know the values. What do I need to do then?
Thank you!
madhan ravi
madhan ravi el 31 de Oct. de 2018
Editada: madhan ravi el 31 de Oct. de 2018
Anytime :) couldn’t help you though because have no experience in statistics field :)
No worries, thank you friend :)
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

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 31 de Oct. de 2018

Comentada:

el 6 de Mzo. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by