Hi Pooneh,
I understand that you want to generate random values in two dimension which are correlated based on a correlation function.
Here are the steps to generate a two-dimensional Gaussian random field with specified mean, covariance, and correlation function in MATLAB:
1. Define the correlation function. For example, the Markovian correlation function can be defined as C(x, y, a) = exp(-sqrt((x - y).^2) / a), where x and y are the spatial coordinates and a is the correlation length.
2. Define the grid of points where you want to generate the random field. For example, you can create a 2D grid of n by n points using the “meshgrid” function with the “linspace” function to define the range of x and y coordinates. You can refer to these links for the same:
3. Calculate the covariance matrix for the grid of points based on the correlation function. For example, you can use a nested for-loop to compute the covariance between each pair of points using the correlation function.
4. Generate a set of uncorrelated Gaussian random variables with zero mean and unit variance using the “randn” function. You can refer to the link for help regarding the function:
5. Use the Cholesky decomposition to transform the uncorrelated variables to a set of correlated variables with the desired covariance matrix. The “chol” function can be used to compute the Cholesky decomposition. Here’s the link you can refer for the same :
6. Transform the correlated variables to the desired random field with the specified mean and standard deviation. For example, you can use the reshape function to convert the correlated variables to a 2D matrix and then apply a linear transformation to set the mean and standard deviation of the random field.