MATLAB: How to create a specific matrix from a regular matrix

MATLABspecific matrix

I wanna create a specific matrix B from a regular matrix A as following in Matlab. Is there anyone who can help me to use a better method to generate it, not for loop? The matrix size could be various. In example, it's 3 by 3 matrix. It could be 3 by n matrix. Thanks
A=[ a b c;
d e f;
g h i]
B=[a 0 0;
d b 0;
g e c;
0 h f;
0 0 i]

Best Answer

A=[ 1 2 3;4 5 6;7 8 9]
[n,m]=size(A)
B=[A;zeros(n-1,m)]
out=cell2mat(arrayfun(@(x) circshift(B(:,x),[x-1 0]),1:m,'un',0))