MATLAB: Change diagonal place

diag

How can I switch places the diagonal and the first column from a square matrix?

Best Answer

a= magic(3)
a =
8 1 6
3 5 7
4 9 2
>> b=a;
>> for i =2:size(a,1)
b(i,1:i)= fliplr(a(i,1:i));
end
b
b =
8 1 6
5 3 7
2 9 4