Lecturer

Basic Matrix Functions:- 
magic(n) 
returns an n-by-n matrix constructed from the integers 1 through n^2 with 
equal row and column sums. The order n must be a scalar greater than or 
equal to 3.

 

>> M = magic(3)  

 

M =   
   8    1    6  
   3    5    7  
   4    9    2

 

Sum(A) 
>>A=[1 2  3  
          4 5 6];  
If A is a vector, sum(A) returns the sum of the elements. 
If A is a matrix, sum(A) treats the columns of A as vectors, returning a row 
vector of the sums of each column.

 

>>sum(A)  
Ans=  
  5   7   9  
A=[1 2 
     3 4   
     5 6];  
>> sum(A) 
ans = 9    12