EDIT:
As pointed out by @PeterO and @pjs in the comments, correlation is only preserved under linear transformations. Since I apply a non linear transormation, the correlation between the variables do not correspond to the desired correlation.
This answer is not complete.
Original Answer:
Using gaminv
you will be able to transform multivariate normal random numbers into gamma one.
n = 100; % # of random number
mu = [0,0,0]; % [muX1, muX2, muX3]
rho = [1.0 0.5 0.7;
0.5 1.0 0.4;
0.7 0.4 1.0] % covariance matrix
Z = mvnrnd(mu, rho, n); %Generate multivariate corralated random number
U = normcdf(Z,0,1); %Compute the CDF
%gamma distribution parameter
a = 2
b = 1
%transform your normal multivariate number into gamma distribution with gaminv
X = [gaminv(U(:,1),a,b) gaminv(U(:,2),a,b) gaminv(U(:,3),a,b)];
% Variable extraction:
X1 = X(:,1);
X2 = ...
Result using only X1 and X2 and a covariance factor of 0.8:
