Created
March 12, 2014 13:09
-
-
Save werediver/9506561 to your computer and use it in GitHub Desktop.
Scilab function returning 2D matrix antidiagonal by index.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//-->adiag([1 2 3 4; 5 6 7 8; 9 10 11 12],3)' | |
// ans = | |
// 9. 6. 3. | |
function [v] = adiag(x, z) | |
// 2D matrix antidiagonal | |
[N, M] = size(x) | |
// The total diagonals count | |
Z = N + M - 1 | |
// The current diagonal length | |
z_len = min(z, Z - z + 1, min(N, M)) | |
i = max(z, N * (z - N + 1)) | |
step = N - 1 | |
v = x(i : step : i + step * z_len - 1) | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment