Computational Intelligence, SS08 2 VO 442.070 + 1 RU 708.070 last updated:
General
Course Notes (Skriptum)
Online Tutorials
 Introduction to Matlab Neural Network Toolbox OCR with ANNs Adaptive Filters VC dimension Gaussian Statistics PCA, ICA, Blind Source Separation Hidden Markov Models Mixtures of Gaussians Automatic Speech Recognition
Practical Course Slides
Homework
Exams
Animated Algorithms
Interactive Tests
Key Definitions
News
mailto:webmaster

Unterabschnitte

# More About Matrices and Arrays

## The Colon Operator

The colon, :, is one of the most important Matlab operators. It occurs in several different forms. The expression
>> 1:10

ans =
1     2     3     4     5     6     7     8     9    10
is a row vector containing the integers from 1 to 10. To obtain nonunit spacing, specify an increment. For example,
>> 20:-2:0

ans =
20    18    16    14    12    10     8     6     4     2     0
Subscript expressions involving colons refer to portions of a matrix.
>> P(1,3:4)

ans =
-6     1
or
>> P(1,:)

ans =
3     5    -6     1
The colon by itself refers to all the elements in a row or column of a matrix and the keyword end refers to the last row or column. As index also other matrices could be used, e.g.
>> P(:,[1 3 4])

ans =
3    -6     1
-2     4     9
or
>> P(:,randperm(4))

ans =
1    -6     3     5
9     4    -2     5
The logical vectors created from logical and relational operations can be used to reference subarrays. For example
>> P(:,y)

ans =
5    -6     1
5     4     9
specifies the elements of P where the elements of y are nonzero and
>> P(P>1)'

ans =
3     5     5     4     9
displays all positive elements of P as a row vector.

## Concatenation and Deletion

Concatenation is the process of joining small matrices to make bigger ones. In fact, you made your first matrix by concatenating its individual elements. The pair of square brackets, [], is the concatenation operator.
>> P1 = [3 5 1 0.1; 8 4 2.2 0];
>> [P1 P; P P1]
To delete for instance a column of a matrix, use
>> X = P;
>> X(:,2) = []

X =
3    -6     1
-2     4     9
and the remaining elements are shaped into a smaler matrix.

## Array Operations

Arithmetic operations on arrays are done element-by-element. Matlab uses a decimal point as part of the notation for multiplicative array operations. The list of operators includes multiplication
>> P.*P1

ans =
9.0000   25.0000   -6.0000    0.1000
-16.0000   20.0000    8.8000         0
division
>> P./P1

ans =
1.0000    1.0000   -6.0000   10.0000
-0.2500    1.2500    1.8182       Inf
or array power
>> P.^P1

ans =
1.0e+03 *
0.0270    3.1250   -0.0060    0.0010
0.2560    0.6250    0.0211    0.0010
as well as left division . and unconjugated array transpose .'.

## Special Matrices

Matlab provides five functions that generate basic matrices.

zeros   All zeros

ones All ones

rand Uniformly distributed random elements

randn Normally distributed random elements

eye Identity matrix

## Workspace

The commands, who and whos, show the current contents of the workspace. The who command gives a short list, while whos also gives size and storage information.

To delete all the existing variables form the workspace, enter
>> clear all
The save command preserve the contents of the workspace in a MAT-file that can be read withe the load command in a later Matlab session. For example
>> save August17th
save the entire workspace contents in the file August17th.mat. If desired, you can save only certain variables by specifying the variable names after the filename.