Sunteți pe pagina 1din 5

PRESENTATION

Matlab
One Dimensional Numeric Array
The expression is a row vector, which is a horizontal arrangement of the elements. We can also express the
vector as a column vector, which has a vertical arrangement. A vector can have only one column, or only one
row. Thus, a vector is a one-dimensional array.

Functions related to vector

Sum (x)
S = sum(A) returns the sum of the elements of A along the first array dimension whose size does not equal 1.
Examples
Create a vector and compute the sum of its elements.
A = 1:10;
S = sum(A)
S=55

Mean(x)
Average or mean value of arrays
Example
A = [1 2 3; 3 3 6; 4 6 8; 4 7 7]; mean(A) ans = 3.0000 4.5000 6.0000
Length(x)
Length of largest array dimension
L = length(X) returns the length of the largest array dimension in X. For vectors, the length is simply the number
of elements. For arrays with more dimensions, the length is max(size(X)). The length of an empty array is zero.

Max(x)
Maximum elements of an array
M = max(A) returns the maximum elements of an array.

Min(x)
Minimum elements of an array
M = min(A) returns the minimum elements of an array.
If A is a vector, then min(A) returns the minimum of A.

Array Addressing
Array indices are the row and column numbers of an element in an array and are used to keep track of the
array's elements. For example, the notation v(5) refers to the fifth element in the vector v, and A(2,3) refers to
the element in row 2, column 3 in the matrix A. The row number is always listed first! This notation enables you
to correct entries in an array without retyping the entire array.
For example, to change the element in row 1, column 3 of a matrix D to 6, you can type D(1,3) = 6. The colon
operator selects individual elements, rows, columns, or .sub arrays . of arrays.
Here are some examples:
A(:,n) Refers to the elements in all the rows of column n of the matrix A.
A(n,:) Refers to the elements in all the columns of row n of the matrix A.

Empty array
The empty array contains no elements and is expressed as []. Rows and columns can be deleted by setting the
selected row or column equal to the empty array. This step causes the original matrix to collapse to a smaller
one. For example, A(3,:) = [] deletes the third row in A

Predefined Variables and keywords


There are seventeen words, called keywords, that are reserved by MATLAB for various purposes, and cannot be
used as variable names. These words are:
break case catch continue else elseif end for function global if otherwise persistent return switch try while

Rearrange a matrix
Rearrange a matrix A that has r rows and s columns to have m rows and n columns. r times s must be equal to
m times n.
reshape(A,m,n)
>> A=[5 1 6; 8 0 2];
A=516
802
>> B = reshape(A,3,2)
B=50
86
12

Determinant
The determinant is a function that associates with each square matrix A a number, called the determinant of the
matrix. The determinant is typically denoted by det(A) or |A|. The determinant is calculated according to specific
rules. The determinant of a square matrix can be calculated with the det command

S-ar putea să vă placă și