How do I get prctile function to work?

조회 수: 4 (최근 30일)
Jonathan
Jonathan 2013년 9월 10일
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
the cyclist
the cyclist 2013년 9월 10일
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 2013년 9월 10일
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.

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

답변 (2개)

the cyclist
the cyclist 2013년 9월 10일
prctile() is a function in the Statistics Toolbox. Type
ver
at the command prompt to see your list of available toolboxes.
  댓글 수: 3
the cyclist
the cyclist 2013년 9월 10일
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 2013년 9월 10일
Okay, thank you very much!

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


the cyclist
the cyclist 2013년 9월 10일
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
Jonathan
Jonathan 2013년 9월 10일
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.

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by