Generate t distributed random variable in matlab How can we generate t distributed random variables with given mean and covariance in matlab.
trnd is a function in matlab but we can get random variable with different degrees of freedom but how to get random variable with given mean and covariance? 
 A: Indeed, there is no ready function in MATLAB for generating random numbers from the general t-distribution and I could not find with quick googling any readily available function. Assuming that by covariance, you mean either variance (scalar case) or covariance matrix here is one way that should work.
Let the desired degree of freedom be $\nu$, the mean $m$ and variance $v^2$. (Note that we must have $\nu > 2$ for the variance to be finite!) You first need to compute the scale parameter $\sigma$ that is connected to the variance $v^2$ by $v^2 = \sigma^2 \frac{\nu}{\nu-2}$ from which $\sigma = v \sqrt{\frac{\nu-2}{\nu}}$. Then you use the fact that if $x$ follows standard t-distribution (zero mean, unit scale) with degree of freedom $\nu$ then $m + \sigma x$ follows the desired t-distribution. The matlab function trnd($\nu$) gives you the sample from $x$.
So in short, you generate t-distributed random variable using x=trnd($\nu$) and then y = m+v*sqrt(($\nu$-2)/$\nu$)*x follows t-distribution with the desired mean and variance. This should be easy to implement and test.
In the multidimensional case where the mean vector $m\in\mathbb{R}^p$ and covariance matrix $S\in\mathbb{R}^{p\times p}$ is symmetric and positive definite you do similarly, except that you need to compute the Cholesky factorization $LL^T = S$ and you can use the matlab function mvtrnd which wants the correlation structure as input which can be set to the identity matrix.
So in multidimensional case generate t-distributed random variable using x=mvtrnd(C,$\nu$)' (where C is $p\times p$ identity matrix), L = chol(S)' then y = m+sqrt(($\nu$-2)/$\nu$)*
L*x follows t-distribution with the desired mean and covariance matrix.
