## How to find the quantiles of the estimated distribution.

### Bo (view profile)

on 6 May 2013
Accepted Answer by the cyclist

### the cyclist (view profile)

I have a random variable E follows a estimated distribution.Now I put the values of E in a vector,for example e=[-1:1], and the cumulative probability of each element in vector e is filled in vector P. How can I find the 95% quantile of E ?

## Products

No products are associated with this question.

### the cyclist (view profile)

Answer by the cyclist

### the cyclist (view profile)

on 6 May 2013

So, if I understand, the vector P is effectively the cumulative distribution function (CDF). So, you just need to find which value of P is closest to 0.95. You could this this with

```[~,idx95] = min(abs(P-0.95));
```

Then, to find the corresponding value of e, you could do

```e_95 = e(idx95);
```

If P is not fine-grained enough, you may need to do some kind of interpolation as well.

Bo

### Bo (view profile)

on 7 May 2013

Thanks for your response and patience

I thought I did not articulate the problem well and my awkward English made you confused.

My work flow was follow:firstly,I got a range of values of ε and formed a unsorted vector E. Since the vector just include the values of random variable ε and the vector couldn't present the probability characteristics of the variable, So I couldn't apply the quantile() function directly to E to get the quantiles I need.

Secondly, I apply a cumulative function whose form was given(not included in Matlab) to E and calculate the cumulative probability values refer to each element of E, then form another vector P in which the order of elements is as the same as in E.

Right now what I am wanna figure out is that, the vector P could be sorted automatically after I sorted the vector E? when I got the two sorted vectors how can I calculate the (1-A)/2 and (1+A)/2 quantiles of the random variable ε? For example:E=[3,4,2,1]; P=[0.75,0.92,0.3,0.1] Each element in E may be different.

Postscripts:

You may ask me "why don't you sort the vector E first then calculate the vector P ?" because I a newcomer and have just started to learn how use the Matlab to do calculating So I am wanna know that : If I have two vectors or matrixes with the same column dimensions, when I sort one of them,is there a method or process can rearrange the other one with the same order along the column direction

the cyclist

### the cyclist (view profile)

on 7 May 2013

Just commenting on your last question (then I will try to give the broader problem some thought). There are a couple ways to do what you want, I think.

One way is to use the second index of the sort command:

```[sorted_x, index] = sort(x);
```

The index will give the ordering, which could then be used for other vectors.

You could also put the vectors into one matrix, and use the sortrows() function.

```doc sortrows
```

for details.

Bo

### Bo (view profile)

on 7 May 2013

Thanks for your help ~!:P

#### Join the 15-year community celebration.

Play games and win prizes!

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi