Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
A=[a_11, a_12; a_21, a_22]
斜对角线是[a_12, a_21]。现在,我翻转矩阵并使用 diag。
[a_12, a_21]
作为 and 的替代方法fliplr,diag您可以像这样直接索引到矩阵中:
fliplr
diag
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