Problem in calculating 30th percentile

Hello everyone,
I am trying to calculate the 30th percentile. I tried using prctile function but didn't get the result. I've calculated 50th percentile (median) as below:
Temp = 437x1 double:
Area = 437x1 double;
[G,grpTemp] = findgroups(round(Temp));
medianAr = splitapply(@median,Area,G);
Any suggestions how to calculate 30th percentile?

 Respuesta aceptada

Rik
Rik el 21 de Nov. de 2021

0 votos

Write a function that calculates the 30th percentile for a vector. Then provide the handle to that function to splitapply.
The easiest way to calculate the 30th percentile is probably to sort your vector and index it. Note that you may need to average 2 values if the index is not an integer.

4 comentarios

Star Strider
Star Strider el 21 de Nov. de 2021
The prctile function should work. I wonder what the problem is with it?
I would use sort and interp1 instead of the index, unless the index (and not the exact value) is required. That should provide a reasonable approximation.
@Star Strider I tried doing like this, but it didn't work
Y = splitapply(@prctile,[30], Area,G);
I didn't understand the purpose of using sort and interp1 here. Kindly explain.
splitapply(@(x) prctile(x,30),Area,G)
And the other remarks were about my suggestion to write your own function.
Zhou Ci
Zhou Ci el 22 de Nov. de 2021
Thanks!

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

el 21 de Nov. de 2021

Comentada:

el 22 de Nov. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by