From: Kashif on
Hi All,

I need to find the sum of cross diagonal entries.

If A =[x11 , x12, x13;
x21 , x22, x23;
x31 , x32, x33];

then I need the sum of x13,x22,x31.
I need to do this for a general N by N matrix.

Best Regards.
From: Andy on
"Kashif " <rajakashif(a)gmail.com> wrote in message <i41acc$egs$1(a)fred.mathworks.com>...
> Hi All,
>
> I need to find the sum of cross diagonal entries.
>
> If A =[x11 , x12, x13;
> x21 , x22, x23;
> x31 , x32, x33];
>
> then I need the sum of x13,x22,x31.
> I need to do this for a general N by N matrix.
>
> Best Regards.

A=magic(5); % sample data
[n, n] = size(A); % we know A is square
antidiagonal = 0;

for ix = 1:n
antidiagonal = antidiagonal + A(ix, n-ix+1);
end
From: ImageAnalyst on
% Setup/initialization
A=magic(6) % Sample data
[rows columns] = size(A) % Get size of array.
linearIndices = columns:(columns-1):rows*columns-1 % Just for your
info, or you can plug in below.

% Here's the answer:
sumAntiDiagonal = sum(A(columns:(columns-1):end-1))
From: Walter Roberson on
Kashif wrote:

> I need to find the sum of cross diagonal entries.
>
> If A =[x11 , x12, x13; x21 , x22, x23;
> x31 , x32, x33];
>
> then I need the sum of x13,x22,x31.
> I need to do this for a general N by N matrix.

N = length(A);
sum(A(N:N-1:end-N+1))
From: Roger Stafford on
"Kashif " <rajakashif(a)gmail.com> wrote in message <i41acc$egs$1(a)fred.mathworks.com>...
> Hi All,
>
> I need to find the sum of cross diagonal entries.
>
> If A =[x11 , x12, x13;
> x21 , x22, x23;
> x31 , x32, x33];
>
> then I need the sum of x13,x22,x31.
> I need to do this for a general N by N matrix.
>
> Best Regards.
- - - - - - - -
Or

trace(fliplr(A))

Roger Stafford