Prev: meet mothen 300,000 activated hot people, free live video chat, live movies...
Next: %VAL problems with gfortran and mex
From: Kashif on 12 Aug 2010 13:18 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 12 Aug 2010 13:25 "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 12 Aug 2010 13:46 % 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 12 Aug 2010 13:54 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 12 Aug 2010 13:58
"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 |