Entering Matrix

  • A = [16 3 2 13; 5 10 11 8; 9 6 7 12; 4 15 14 1]
    • explicit list
    • load from external data files
    • generate from built-in functions
    • create from custom-built functions (M-files)

Column computations preferred

  • Matlab has a preference for working with the columns of a matrix.
    • sum(A)  - sums columns into a row vector
  • To work with rows, transpose a matrix, see below

sum, transpose, diag

  • switch an array as if flipping it upon both axis
  • A'                    - tranpsoses numbers and changes sign of any complex elements
    A'.                   - transposes numbers w/o changing sign
    sum(A')'              - sum rows into a column vector
    diag(A)               - main diagonal elements of an array
    sum(diag(A))          - sum of the main diagonal elements of an array
    fliplr(A)             - flips the array from left to right
    sum(diag(fliplr(A)))  - sum of the antidiagonal
    

Subscipts

  • A(row, col)  - refers to specific element in array
    A(4,2) = A(8)
    

Concatenate or add to a matrix

  • A(4,5) = 17  - granted that the 5th column doesn't exist, it is added, with the number
    
 
technology/matlab/beginner.txt · Last modified: 09.16.2008 18:21 by 96.244.71.32
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki