Here is the correct version of Atul's MATLAB code:

[i,j]=find(fliplr(triu(ones(n))));
M=full(sparse(i,j,v,n,n))';

or more intuitively:

M=zeros(n);
b=fliplr(triu(~M));
M(b)=v;
M=M';

Avoiding loops when doing operations over matrix elements tends to make things much more intuitive in MATLAB.