An interactive introduction to MATLAB

(Jeff_L) #1

8 basic concepts


array withmrows andncolumns is called a matrix of sizem×n. Listings 1.7–
1.10 demonstrate how to create row and column vectors, and matrices in
MATLAB.
Listing 1.7: Creating a row vector
1 >> x = [1 2 3]
2 x =
3 1 2 3


  • Square brackets are used to denote a vector or matrix.

  • Spaces are used to denote columns.


Listing 1.8: Creating a column vector
1 >> y = [4; 5; 6]
2 y =
3 4
4 5
5 6


  • The semicolon operator is used to separate columns.


Listing 1.9: The transpose operator
1 >> x'
2 ans =
3 1
4 2
5 3

7 >> y'
8 ans =
9 4 5 6


  • The single quotation mark'transposes arrays, i.e. the rows and columns
    are interchanged so that the first column becomes the first row etc...


A more efficient method for entering vectors, especially those that con-
tain many values, is to use ranges. Instead of entering each individual value
separately, a range of values can be defined as shown in Listing 1.10.
Free download pdf