MATLAB: I have a nxn matrix. How to get two variables [m,n] corresponding to the elements of the row of the matrix.(Kindly see the image)

vector elements or num2cell

Best Answer

B = reshape(A.',[],1);
C = hankel(B(1:end-1),B(end-1:end));
m = C(:,1);
n = C(:,2);
or
s = size(A,2);
m = A(:,1:s-1);
n = A(:,2:s);