I want to replace the diag between two matrices in matlab, for example: a =
1 1 1
1 1 1
1 1 1
b =
2 2 2
2 2 2
2 2 2
I want the function to do this: b =
1 2 2
2 1 2
2 2 1
a =
2 1 1
1 2 1
1 1 2
but instead of getting the final result, I am getting the all the inbetween results in the for loop// what i am doing wrong?
function [x] = may( a,b )
l1=length(diag(a));
l2=length(diag(b));
n=diag(a);
m=diag(b);
for i=1:l1
b(i,i)=n(i)
end
for j=1:l1
a(j,j)=m(j)
end
end