## What is the code?

Asked by eren eren

### eren eren (view profile)

on 6 Dec 2012
Accepted Answer by José-Luis

### José-Luis (view profile)

I want to generate random numbers. But i want it like this. for example i want to generate random numbers for The gamma distribution coefficient of skewness 2.

How can i do this?

## Products

No products are associated with this question.

### José-Luis (view profile)

on 6 Dec 2012
Edited by José-Luis

### José-Luis (view profile)

on 6 Dec 2012
` doc gamrnd`

The skewness is a function of one of the two parameters of the distribution, that you can set as you see fit. You just need to set it so the skewness is two (look at the wikipedia article on the gamma distribution).

eren eren

### eren eren (view profile)

on 6 Dec 2012

no i understood that but in gamrnd don't have skewness a place to enter.

José-Luis

### José-Luis (view profile)

on 13 Dec 2012

When you do this:

i write this on matlab skewness = 2; scale = 1; shape = 2./sqrt(skewness); x=gamrnd(shape,scale) s=skewness(x)

Skewness becomes a variable, and overshadows the built-in skewness function in Matlab. It is good practice not to do that, as problems as the one got might pop-up (you think you are calling a function but you are in fact trying to access a variable).

After clearing your work space to make sure there is no variable called skweness in it, do this instead:

``` ske = 2;
sca = 1;
shap = 1/sqrt(2);
x = gamrnd(shap,sca,[1000 1]);
your_skew = skewness(x); ```

Please accept an answer if it helped you.

eren eren

### eren eren (view profile)

on 13 Dec 2012

yes it is working. can i use this, beta, chi squre etc. distributions?

### Jonathan Sullivan (view profile)

Answer by Jonathan Sullivan

### Jonathan Sullivan (view profile)

on 6 Dec 2012

skewness is simple 2 divided by the square root of the shape parameter for gamma distributions. Here's an example.

```skewness = 2;
scale = 1;
shape = 2./sqrt(skewness);
gamrnd(shape,scale)
```

José-Luis

### José-Luis (view profile)

on 13 Dec 2012

What does your code look like? And the error is? It is hard to help you without details.

eren eren

### eren eren (view profile)

on 13 Dec 2012

i write this on matlab skewness = 2; scale = 1; shape = 2./sqrt(skewness); x=gamrnd(shape,scale) s=skewness(x)

and error is;

??? Attempted to access skewness(0.412164); index must be a positive integer or logical.

José-Luis

### José-Luis (view profile)

on 13 Dec 2012

Please see the comment to my original answer.

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

### Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.