As an alternative to fliplr and diag, you can index directly into the matrix like this:
A = magic(3);
s = length(A);
idx = s:(s-1):(s*(s-1)+1);
%# for anti-diagonal, use the following
%#idx = (s*(s-1)+1):(-s+1):s;
skewDiag = A(idx)
skewDiag =
4 5 6
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.OkRead more