How do I get prctile function to work?

6 visualizaciones (últimos 30 días)
Jonathan
Jonathan el 10 de Sept. de 2013
Here is my code for what I am trying to do:
Iterations = 5000;
for i = 1:Iterations
format rat;
Beta = 8/13;
U = rand(1);
condition1 = U <= 8/13;
T(condition1) = sqrt(8*U/13);
condition2 = U > 8/13;
T(condition2) = 1 - sqrt(5*(1 - U)/13);
N = floor(80 + 130*T);
Zmatrix = floor(170 + 316*rand(1,N));
x(i) = sum(Zmatrix);
end
hist(x)
m = mean(x)
v = var(x)
prctile(x,25)
Basically, I have created an array of value x, and successfully created a histogram from the data. However, the prctile(x,25) function is not working.
What do I have to do to get Matlab to understand the prctile function? I have version 7.12.0 (R2011a). Any ideas?
  2 comentarios
the cyclist
the cyclist el 10 de Sept. de 2013
Can you be more specific by what you mean by "not working"? Give the full error message if you get one. If it runs, but gives a value that you think is wrong, please explain why.
Jonathan
Jonathan el 10 de Sept. de 2013
The message I get in the Command Window when I try to run the code is:
??? Undefined function or method 'prctile' for input arguments of type 'double'.
Error in ==> m_file_hw1_problem3 at 21 prctile(x,25)
So I am not getting a value at all. It just gives me this error message.

Iniciar sesión para comentar.

Respuestas (2)

the cyclist
the cyclist el 10 de Sept. de 2013
prctile() is a function in the Statistics Toolbox. Type
ver
at the command prompt to see your list of available toolboxes.
  3 comentarios
the cyclist
the cyclist el 10 de Sept. de 2013
That is definitely the issue.
Your options:
  • Buy the Statistics Toolbox
  • Program this one function yourself
  • Look in the File Exchange to see if someone has contributed a percentile function that you could download and use.
Each of these options has pros and cons, depending on your knowledge, wealth, and time available.
Jonathan
Jonathan el 10 de Sept. de 2013
Okay, thank you very much!

Iniciar sesión para comentar.


the cyclist
the cyclist el 10 de Sept. de 2013
I don't know why you chose
format rat
which I am going to ignore for now.
I get that
m = 4.8e4
and
prctile(x,25) = 4.3e4
(approximately).
Both of these values look quite reasonable, given your histogram. Do you get something different? I am running R2013a.
  1 comentario
Jonathan
Jonathan el 10 de Sept. de 2013
Oops, I meant to post my reply here. Not sure if it matters...
The message I get in the Command Window when I try to run the code is:
??? Undefined function or method 'prctile' for input arguments of type 'double'.
Error in ==> m_file_hw1_problem3 at 21 prctile(x,25)
So I am not getting a value at all. It just gives me this error message.

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by